﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OSISDynamicTranslation;
using OpenSISInstall;
using OSISFunction;
using OpenSIS.OpenSISWCFServiceReference;
using OpenSISStudentListControl;


public partial class Student_EditStudentInfo : System.Web.UI.Page
{
    DropDownList ddlSchoolName = new DropDownList();
    DropDownList ddlFullYear = new DropDownList();
    DropDownList ddlLevel1 = new DropDownList();
    int InitialFieldId = 0;
    static string AddTableList = "";
    private HtmlTableRow dTRow;
    private HtmlTableCell dTCell;
    private HtmlTableRow dTAddRow;
    private HtmlTableCell dTAddCell;
    private HtmlTableCell dTAddCell1;
    private HtmlTableCell dTAddCell2;
    private HtmlTableCell dTCell1;
    private HtmlTableCell dTCell2;
    private HtmlTableCell dTAdditionalContCell;
    private HtmlTableCell dTAdditionalContCell1;
    private HtmlTableCell dTAdditionalContCell2;
    private HtmlTableRow dTAdditionalContRow;
    private HtmlTable dTAdd;
    DataRow drvacc;
    static int AlertRowId = 0;
    static int ImmuRowId = 0;
    static int NurseVisitRowId = 0;
    StudentListControl StuListCont = new StudentListControl();
    string AllFieldID;
    protected void Page_Load(object sender, EventArgs e)
    {
       

        PopulateCategoryTree();
        PopupateInitialFields();
        if (!Page.IsPostBack)
        {
            //PopupateInitialFields();
            string studentid = Request.QueryString["studentid"].ToString();
            hdnStudentId.Value = studentid;
            PopulateFieldData();
            //PopulateMasterDropdownFullYear();

            //*************************03/05/2010

           ////// ClearSession();
        }
        PopulatePicture();
        if (Session["StudentImage"] != null)
        {

            divPhotoUpload.Style.Add("background-image", "url(" + Session["StudentImage"].ToString().Replace("~", "..") + ")");
            lblUploadPhoto.Text = "Change Photo";
        }


        SISInstall SISInstall = new SISInstall();
        //SchoolBL schoolAdd = new SchoolBL();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();


        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }

        CalAddAttStartDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalAddEndDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalEditAttStartDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalEditEnddate.Format = SISInstall.CalenderDateFormat.ToString().Trim();

        


    }
    
    protected void PopulatePicture()
    {
        //StudentInfoBL StdInfo = new StudentInfoBL();
        OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
        int StudentID = Convert.ToInt32(hdnStudentId.Value);
        //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        DataTable dtphoto = StdInfo.GetPhotoURL(SchoolID, StudentID);
        if (dtphoto.Rows.Count > 0)
        {
            divPhotoUpload.Style.Add("background-image", "url(" + dtphoto.Rows[0]["name"].ToString() + ")");
            lblUploadPhoto.Text = "Change Photo";
        }
        else
        {
            divPhotoUpload.Style.Add("background-image", "url(../App_Themes/main/images/no_pic.png)");
            lblUploadPhoto.Text = "Upload Photo";
        }
    }

    

    public void PopulateCategoryTree()
    {
        try
        {

            //StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            if (SchoolID == 0)
            {
                SchoolID = Convert.ToInt32(Session["SchoolID"].ToString());
            }
            DataTable dt = schoolcategory.GetSchoolSpecificCategoryStudentBusiness(SchoolID.ToString(), Session["MLUICulture"].ToString());
            TreeView1.Nodes.Clear();
            string[,] YearNodes = new string[100, 4];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TreeNode TreeNodeCategory = new TreeNode();
                YearNodes[i, 0] = dt.Rows[i]["Cat_Name"].ToString();
                YearNodes[i, 1] = dt.Rows[i]["Cat_Id"].ToString();

                TreeNodeCategory.Text = YearNodes[i, 0];


                TreeNodeCategory.Value = YearNodes[i, 1] + "," + i;
                TreeView1.Nodes.Add(TreeNodeCategory);
                TreeView1.ExpandAll();
            }
        }
        catch { }
    }

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        try
        {



            StoreFieldDataIntoDatatable();

            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {
                this.dTable.Rows.RemoveAt(k);
            }


            //enrollment
            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();
                DataStoreProgramForVaccination();
                // btnAlertSave_Click(sender, e);
            }
            if (hdnCatId.Value.ToString() == "4")
            {
               //DataStoreEnrInfo();

                StoreSchoolInfoDataIntoDatatable();
            }
            //23
            if (hdnCatId.Value.ToString() == "8")
            {

                DataStoreProgram();
                DataStoreProgramForGift();
            }

            hdnCatId.Value = TreeView1.SelectedNode.Value.Split(",".ToCharArray())[0];
            PopulateInSelectedNodeChange();

            if (hdnCatId.Value.ToString() == "5")
            {
                PopulateVccinationValue();
                PopulateMedicalInfoFieldData();
                // PopulateVaccinationFieldData();

            }
            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();
                //**********23
                //Program();

            }
            PopulateFieldData();

        }
        catch (Exception x)
        {
            string s = x.Message;
        }

    }

    protected void btnNext_Click(object sender, ImageClickEventArgs e)
    {
        try
        {

            StoreFieldDataIntoDatatable();
            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {
                this.dTable.Rows.RemoveAt(k);
            }

            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();

                DataStoreProgramForVaccination();
            }


            //enrollment
            if (hdnCatId.Value.ToString() == "4")
            {
                //DataStoreEnrInfo();
                StoreSchoolInfoDataIntoDatatable();
            }

            //*********23
            //Program

            if (hdnCatId.Value.ToString() == "8")
            {

                DataStoreProgram();
                DataStoreProgramForGift();
            }

            PopulateNextFields();

            if (hdnCatId.Value.ToString() == "5")
            {

                PopulateMedicalInfoFieldData();
                //PopulateVaccinationFieldData();
                PopulateVccinationValue();
            }
            //enrollment
            if (hdnCatId.Value.ToString() == "4")
            {

                PopulateSchoolFieldData();
            }


            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();


            }

            PopulateFieldData();
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }


    }

    protected void btnPrev_Click(object sender, ImageClickEventArgs e)
    {
        try
        {

            StoreFieldDataIntoDatatable();

            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {

                this.dTable.Rows.RemoveAt(k);

            }

            if (hdnCatId.Value.ToString() == "5")
            {

                StoreMedicalInfoFieldDataIntoDatatable();
                DataStoreProgramForVaccination();

            }

            //enrollment
            if (hdnCatId.Value.ToString() == "4")
            {
                //DataStoreEnrInfo();
                StoreSchoolInfoDataIntoDatatable();
            }


            //*****23 program

            if (hdnCatId.Value.ToString() == "8")
            {

                DataStoreProgram();
                DataStoreProgramForGift();
            }

            PopulatePreviousFields();

            if (hdnCatId.Value.ToString() == "5")
            {

                PopulateMedicalInfoFieldData();
                // PopulateVaccinationFieldData();
                PopulateVccinationValue();
            }
            //enrollment
            if (hdnCatId.Value.ToString() == "4")
            {

                PopulateSchoolFieldData();
            }

            if (hdnCatId.Value.ToString() == "8")
            {

                PopulateGiftValue();
                PopulateSpecialValue();

                //**********23
                // Program();
            }


            PopulateFieldData();
            //Program();
        }
        catch { }

    }

    protected void PopupateInitialFields()
    {
        // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        StudentListControl StulistCOnt = new StudentListControl();
        try
        {





            int FieldIdpopulate = 0;
            // StudentBL stcategory = new StudentBL();

            // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            IopenSISServiceStudentClient stcategory = new IopenSISServiceStudentClient();
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            DataTable dtCatId = stcategory.GetFirstCategoryStudentBusiness(SchoolID);

            if (dtCatId.Rows.Count > 0)
            {
                if (hdnInitialCatId.Value.ToString() == "")
                {
                    hdnCatId.Value = dtCatId.Rows[0][0].ToString();
                }
                else
                {
                    hdnCatId.Value = hdnInitialCatId.Value.ToString();
                }

                if (hdnCatId.Value.ToString() == "1")
                {
                    divPhotoUpload.Style.Add("Display", "block");
                    divOuter.Style.Add("Display", "block");
                }
                else
                {
                    divPhotoUpload.Style.Add("Display", "none");
                    divOuter.Style.Add("Display", "none");
                }


                foreach (TreeNode tn in TreeView1.Nodes)
                {
                    string t = tn.Value.Split(",".ToCharArray())[0];
                    if (t == hdnCatId.Value.ToString())
                    {

                        tn.Selected = true;

                    }

                }

                if (hdnCatId.Value.ToString() != "3")
                {

                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;

                    //*****sa**********
                    tblProgram.Visible = false;

                    if (hdnCatId.Value.ToString() != "5")
                    {
                        //*******sa******************
                        gvEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        tblSchEnrInfo.Visible = false;
                        if (hdnCatId.Value.ToString() != "4")
                        {
                            if (hdnCatId.Value.ToString() != "8")
                            {
                                int CatId = Convert.ToInt32(hdnCatId.Value);
                                // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                                string CatName = TreeView1.SelectedNode.Text.ToString();
                                DataTable dt = stcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                // ibtnAdd.Visible = false;



                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";


                                //this.dTable.Attributes.Add("class", "darkblue_content");
                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);

                                int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    int j = dt.Rows.Count;

                                    DataRow dr = dt.NewRow();
                                    dt.Rows.Add(dr);

                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);

                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
                                    {

                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {

                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();

                                            dTCell.Attributes.Add("class", "student_grid");

                                            if (dt.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dt.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }

                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";
                                            if (dt.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                FieldIdpopulate = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.ID = "txt" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                txt.CssClass = "textbox2";
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicrchk(ref chk);
                                                    StulistCOnt.populatedynamicrchk(ref chk, FieldIdpopulate);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;

                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        // categoryfields.PopulateGender(ref rdb);
                                                        StulistCOnt.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //  categoryfields.populatedynamicrbtn(ref rdb);
                                                    StulistCOnt.populatedynamicrbtn(ref rdb, FieldIdpopulate);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                ddl.CssClass = "dropdown2";

                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        //categoryfields.populateEthnicity(ref ddl);
                                                        //*******18/05/2010***********
                                                        StulistCOnt.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        //categoryfields.populateLanguage(ref ddl);
                                                        StulistCOnt.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        //  categoryfields.populateCountry(ref ddl);
                                                        StulistCOnt.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        //categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StulistCOnt.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        // stcategory.populatecalender(ref ddl);
                                                        StulistCOnt.populatecalender(ref ddl, SchoolID);
                                                    }

                                                    //****************06/02/2010***********
                                                    if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {


                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicddl(ref ddl);
                                                    StulistCOnt.populatedynamicddl(ref ddl, FieldIdpopulate);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + InitialFieldId;
                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                //  StudentBL stbl2 = new StudentBL();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }

                                            //***************01/05/2010******************
                                            if (dt.Rows[tRows]["FieldType"].ToString() == "6")
                                            {
                                                HiddenField hdnFieldId = new HiddenField();

                                                hdnFieldId.ID = "hdn" + InitialFieldId;
                                                hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                                                control.ID = "uc" + InitialFieldId;
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }

                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dt.Rows.RemoveAt(0);
                                            tRows = 0;
                                            InitialFieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);
                                        //i++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            //**********sa
                            else
                            {
                                //Special and gifted in populateinitialfield
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                //ibtnAdd.Visible = false;
                                btnPrev.Visible = true;
                                //StudentBL schoolcategory = new StudentBL();
                                //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                                //DataTable dtspec = schoolcategory.PopulateSpecialField();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                DataTable dtspec = schoolcategory.PopulateSpecialFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
                                rptrSpecial.DataSource = dtspec;
                                rptrSpecial.DataBind();

                                //***********01/05/2010
                               
                                DataTable SessiondtspecialEdu = (DataTable)Session["SpecialEduForInsert"];
                                if (SessiondtspecialEdu != null)
                                {
                                    rptrSpecEdu.DataSource = SessiondtspecialEdu;
                                    rptrSpecEdu.DataBind();
                                }



                                //DataTable dtgift = schoolcategory.PopulateGiftField();
                                DataTable dtgift = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
                                rptrGiftforadd.DataSource = dtgift;
                                rptrGiftforadd.DataBind();
                                ////if(rptrGiftProg.Items.Count==0)
                                ////{
                               
                                DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
                                if (SessiondtGift != null)
                                {
                                    rptrGiftProg.DataSource = SessiondtGift;
                                    rptrGiftProg.DataBind();
                                }
                                ////        //Program();
                                ////}                              

                            }
                        }
                        //****************
                        else
                        {

                            //enrollment in initialfields
                            // hdnCatId.Value = dt.Rows[0][0].ToString();
                            tblSchEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            gvEnrInfo.Visible = true;

                            int CatId = Convert.ToInt32(hdnCatId.Value);
                            int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
                            DataTable dtschlinfo = stcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());

                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();
                            PopulateSchoolFieldData();

                            if (hdnUpdate.Value != "Update")
                            {
                                DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                                if (SessiondtEnrol != null)
                                {
                                    //***********03/05/2010*************
                                    //gvEnrInfo.DataSource = SessiondtEnrol;
                                    //gvEnrInfo.DataBind();

                                }
                                else
                                {

                                    DataTable dtenrol = stcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);
                                    if (dtenrol.Rows.Count > 0)
                                    {
                                        gvEnrInfo.DataSource = dtenrol;
                                        gvEnrInfo.DataBind();
                                    }
                                    else
                                    {
                                        //***********change22/6/10**************
                                        //DataTable dtEnrol = new DataTable();
                                        //dtEnrol.Columns.Add("Std_Enr_Id");
                                        //dtEnrol.Columns.Add("Enr_Start_Date");
                                        //dtEnrol.Columns.Add("Enr_End_Date");
                                        //dtEnrol.Columns.Add("enrollname");
                                        //dtEnrol.Columns.Add("Exit_Reason");
                                        //dtEnrol.Columns.Add("Start_Condition");
                                        //dtEnrol.Columns.Add("Enr_Code_Id");

                                        //DataRow dr = dtEnrol.NewRow();
                                        //dtEnrol.Rows.Add(dr);
                                        //gvEnrInfo.DataSource = dtEnrol;
                                        //gvEnrInfo.DataBind();


                                    }
                                }
                            }



                        }
                    }
                    else
                    {

                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;
                        //StudentInfoBL StdInfo = new StudentInfoBL();
                        //StudentEditInfoBL StdEditInfo = new StudentEditInfoBL();
                        //StudentBL schoolcategory = new StudentBL();

                        OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
                        OpenSISWCFServiceStudentEditClient StdEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                        int CatId = Convert.ToInt32(hdnCatId.Value);

                        // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);
                        //StdEditInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        //StdEditInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);

                        DataTable dtMedicalInfo = new DataTable();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        rptMedicalInfo.DataSource = dtMedicalInfo;
                        rptMedicalInfo.DataBind();
                        //**************************20
                        //DataTable dtImmu = StdInfo.GetImmunizationFieldValue(SchoolID, StudentID);
                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];



                        ////**************************
                        //if (dtImmu.Rows.Count > 0 && SessiondtImmu == null)
                        //{
                        //    Session.Add("ImmuTable", dtImmu);
                        //    GVImmunization.DataSource = dtImmu;
                        //    GVImmunization.DataBind();
                        //}
                        //else
                        //{
                        
                        //}

                        //*************03/05/2010
                        ////GVImmunization.DataSource = SessiondtImmu;
                        ////GVImmunization.DataBind();


                        DataTable dtAlert = StdInfo.GetMedicalAlertFieldValue(StudentID);
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (dtAlert.Rows.Count > 0 && SessiondtAlert == null)
                        {
                            Session.Add("AlertTable", dtAlert);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            //*************03/05/2010***************
                            //GVMedicalAlert.DataSource = SessiondtAlert;
                            //GVMedicalAlert.DataBind();
                        }

                        DataTable dtNurseVisit = StdInfo.GetNurseVisitFieldValue(SchoolID, StudentID);
                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (dtNurseVisit.Rows.Count > 0 && SessiondtNurseVisit == null)
                        {
                            Session.Add("NurseVisitTable", dtNurseVisit);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            //*************03/05/2010**********
                            //GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            //GVNurseVisitRec.DataBind();
                        }

                        DataTable dtMedicalInfovalue = StdEditInfo.PopulateMedicalInfoValueStudentEdit(StudentID, SchoolID);
                        DataTable MedicalInfoDataFromSession = (DataTable)Session["MedicalInfo"];

                        if (dtMedicalInfovalue.Rows.Count > 0 && MedicalInfoDataFromSession == null)
                        {
                            Session.Add("MedicalInfo", dtMedicalInfovalue);
                            PopulateMedicalInfoFieldData();
                        }
                        else
                        {
                            PopulateMedicalInfoFieldData();
                        }

                        //DataTable dtVaccination = PopulateVacciGrid();
                        //GVVccination.DataSource = dtVaccination;
                        //GVVccination.DataBind();
                        //**********Populate table05/05/2010**********
                        DataTable dtVcea = new DataTable();
                        dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(SchoolID, CatId);
                        rptrVaceField.DataSource = dtVcea;
                        rptrVaceField.DataBind();
                        //rptrVaceFieldEdit.DataSource = dtVcea;
                        //rptrVaceFieldEdit.DataBind();


                        


                        DataTable SessiondtGift = (DataTable)Session["VaccinationForInsert"];
                        if (SessiondtGift != null)
                        {
                            rptrVccination.DataSource = SessiondtGift;
                            rptrVccination.DataBind();
                        }

                    }

                }

                else
                {
                    //******************22
                    TMInfo.Visible = false;
                    tblSchEnrInfo.Visible = false;
                    tblProgram.Visible = false;

                    // StudentInfoViewBL schoolcategory = new StudentInfoViewBL();
                    //StudentBL schoolcategory = new StudentBL();
                    //StudentSetupBL StSuBL = new StudentSetupBL();

                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                    OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();


                    hdnCatId.Value = hdnInitialCatId.Value;
                    //hdnInitialCatId.Value = hdnCatId.Value;
                    int CatId = Convert.ToInt32(hdnCatId.Value);
                    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    SchoolID = Convert.ToInt32(Session["SchoolID"].ToString());
                    // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                    // string CatName = TreeView1.SelectedNode.Text.ToString();
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    //ibtnAdd.Visible = true;

                    // int FieldId = 0;
                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;
                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");
                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);

                    }

                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        // tRows = 0;
                        int L = 0;

                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {

                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";

                                this.dTCell = new HtmlTableCell();

                                //dTCell.Attributes.Add("class", "student_grid");
                                //this.dTCell.InnerHtml = "<div style=padding-left:10px;>" + dtFields.Rows[L]["FieldName"].ToString() + "</div>";

                                //dTCell.Attributes.Add("class", "darkblue_content");
                                //dTCell.Align = "left";
                                //dTCell.VAlign = "top";

                                // this.dTCell.InnerText = dtFields.Rows[L]["FieldName"].ToString() + " : ";
                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {

                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                    int FieldIdpopulates = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //    schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);

                                    // int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount();
                                    // if (addressfieldcount > 0)
                                    // {
                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdpopulates, Session["MLUICulture"].ToString());
                                    //if (dtaddressfields ==null)
                                    //{
                                    //     string PrevSessionTable = "First";
                                    //     DataTable DataFromSession = (DataTable)Session[PrevSessionTable];
                                    //     dtaddressfields = DataFromSession;
                                    //}

                                    // DataRow dra = dtaddressfields.NewRow();
                                    // dra["FieldName"] = dtFields.Rows[tRows]["FieldName"].ToString();
                                    // dtaddressfields.Rows.InsertAt(dra, 0);
                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;

                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);

                                    }


                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {

                                            this.dTAddRow = new HtmlTableRow();
                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {

                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();

                                                //dTAddCell.Attributes.Add("class", "student_grid");
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() != "")
                                                {
                                                    this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                    //dTCell.Align = "right";
                                                    this.dTAddCell1.InnerText = " : ";
                                                }
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");

                                                //--------------------------------------------------------------


                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    txt.ID = "txt" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    txt.CssClass = "textbox2";
                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    chk.ID = "chk" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    chk.Items.Add("Same as Student's Home Address");
                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    rdb.ID = "rdb" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    ddl.ID = "ddl" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //categoryfields.populateState(ref ddl);
                                                        StulistCOnt.populateState(ref ddl);
                                                    }

                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StulistCOnt.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    lbl.ID = "lbl" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //****************01/05/2010***************
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    control.ID = "uc" + InitialFieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }



                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);
                                                dtaddressfields.Rows.RemoveAt(0);
                                                InitialFieldId++;

                                            }



                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);
                                            //dTable.Controls.Add(dTRow);

                                        }
                                        else
                                        {
                                            break;
                                        }
                                        // FieldId++;
                                    }

                                    this.dTCell.Controls.Add(dTAdd);

                                    // }

                                    dtFields.Rows.RemoveAt(0);
                                    //tRows = 0;
                                    this.dTRow.Controls.Add(this.dTCell);
                                }
                            }

                            this.dTable.Controls.Add(dTRow);
                        }
                        else
                        {
                            break;
                        }
                    }



                    string[] SessionTable = AddTableList.Split(';');
                    if (SessionTable.Length > 1)
                    {
                        int SessionTableId = 1;
                        for (int i = 1; i < SessionTable.Length; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                string sessionTab = "Address" + SessionTableId.ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTAdd = new HtmlTable();
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        //dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                // categoryfields.populateState(ref ddl);
                                                StulistCOnt.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StulistCOnt.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }

                                        //**********01/05/2010**************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }


                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        InitialFieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);

                                    this.dTable.Controls.Add(dTRow);

                                }

                                SessionTableId++;
                                // }
                            }

                        }
                    }
                    else
                    {
                        //StudentEditInfoBL stEditInfo = new StudentEditInfoBL();
                        //StudentBL stBL = new StudentBL();

                        OpenSISWCFServiceStudentEditClient stEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient stBL = new IopenSISServiceStudentClient();


                        //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        // stBL.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);

                        int HomeFieldId = 152;

                        int CheckCell = 0;
                        int RowNo = 0;
                        DataTable dtAddField = stEditInfo.GetAdditionalAddressContactSetStudentEdit(StudentID, SchoolID);
                        int mod = dtAddField.Rows.Count % 2;
                        if (mod == 0)
                        {
                            RowNo = dtAddField.Rows.Count / 2;
                        }
                        else
                        {
                            RowNo = Convert.ToInt32(dtAddField.Rows.Count / 2) + 1;

                        }
                        for (int i = 0; i < RowNo; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                DataTable myArrayDataFromSession = stBL.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
                                if (CheckCell == dtAddField.Rows.Count)
                                {
                                    myArrayDataFromSession = null;
                                }


                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");

                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    this.dTAdd.Width = "100%";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtAddField.Rows[CheckCell]["ContactName"].ToString() + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            chk.Items.Add("Same as Student's Home Address");
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                // categoryfields.populateState(ref ddl);
                                                StulistCOnt.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StulistCOnt.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //***********01/05/2010*******************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + InitialFieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + InitialFieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        InitialFieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                    this.dTable.Controls.Add(dTRow);

                                    CheckCell++;
                                }


                                // }
                            }

                        }

                    }

                    phAllFieldHolder.Controls.Add(dTable);

                }

            }
        }
        catch (Exception ex)
        {
            string EX = ex.ToString();
        }
    }

    protected void PopulateInSelectedNodeChange()
    {

        //try
        //{
        //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
        //StudentBL schoolcategory = new StudentBL();
        //StudentSetupBL StSuBL = new StudentSetupBL();

        StudentListControl StuLIstCont = new StudentListControl();
        OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();


        foreach (TreeNode tn in TreeView1.Nodes)
        {
            string t = tn.Value.Split(",".ToCharArray())[0];
            if (t == hdnCatId.Value.ToString())
            {

                tn.Selected = true;

            }

        }
        hdnCatId.Value = TreeView1.SelectedNode.Value.Split(",".ToCharArray())[0];
        string CatName = TreeView1.SelectedNode.Text.ToString();

        hdnInitialCatId.Value = hdnCatId.Value;
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        int CatId = Convert.ToInt32(hdnCatId.Value);
        // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        DataTable dt = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
        //phAllFieldHolder.Controls.Clear();
        //  ibtnAdd.Visible = true;
        if (hdnCatId.Value.ToString() != "1")
        {
            divPhotoUpload.Style.Add("Display", "none");
            divOuter.Style.Add("Display", "none");
        }
        else if (hdnCatId.Value.ToString() == "1")
        {
            divPhotoUpload.Style.Add("Display", "block");
            divOuter.Style.Add("Display", "block");

        }

        int FieldId = 0;
        if (hdnCatId.Value.ToString() == "3")
        {
            //try
            //{
            tblProgram.Visible = false;
            tblSchEnrInfo.Visible = false;
            //sa//*********
            TMInfo.Visible = false;
            int Count = dTable.Rows.Count;

            for (int k = Count - 1; k >= 0; k--)
            {

                this.dTable.Rows.RemoveAt(k);

            }

            hdnCatId.Value = hdnInitialCatId.Value;
            DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());



            this.dTable.CellPadding = 5;
            this.dTable.CellSpacing = 0;
            this.dTable.Border = 0;
            this.dTable.Width = "100%";

            this.dTable.Attributes.Remove("class");
            string[] SessionTable = AddTableList.Split(';');

            int tRows;
            int tCells = 2;
            int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

            int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
            if (tCellsmod != 0)
            {
                tCellsquotient = tCellsquotient + 1;
                DataRow dr = dtFields.NewRow();
                dtFields.Rows.Add(dr);

            }



            for (tRows = 0; tRows < tCellsquotient; tRows++)
            {
                int L = 0;

                if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                {

                    this.dTRow = new HtmlTableRow();

                    for (tCells = 0; tCells < 2; tCells++)
                    {
                        this.dTCell = new HtmlTableCell();

                        this.dTCell2 = new HtmlTableCell();
                        dTCell2.Attributes.Add("class", "bevel_verline");


                        this.dTAdd = new HtmlTable();
                        this.dTAdd.CellPadding = 2;
                        this.dTAdd.CellSpacing = 0;
                        this.dTAdd.Border = 0;
                        this.dTAdd.Width = "100%";

                        DataTable dtaddressfields = null;
                        if (dtFields.Rows[L]["FieldName"].ToString() != "")
                        {
                            dTCell.Align = "left";
                            dTCell.VAlign = "top";

                            //dTCell.Attributes.Add("class", "darkblue_content");
                            this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                            int FieldIdpopulate = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                            // schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                            dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdpopulate, Session["MLUICulture"].ToString());





                            int AddressTableRows;
                            int AddressTableCells = 1;
                            int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                            int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                            if (AddressTableCellsmod != 0)
                            {
                                AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                int j = dtaddressfields.Rows.Count;

                                DataRow dradd = dtaddressfields.NewRow();
                                dtaddressfields.Rows.Add(dradd);

                            }


                            for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                            {
                                AddressTableRows = 0;
                                if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                {

                                    this.dTAddRow = new HtmlTableRow();
                                    for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                    {

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");

                                        this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                        this.dTAddCell1.InnerText = " : ";
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            chk.ID = "chk" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            ddl.CssClass = "dropdown2";
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                            {
                                                //categoryfields.populateState(ref ddl);
                                                StuLIstCont.populateState(ref ddl);
                                            }
                                            if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StuLIstCont.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //*********01/05/2010*************
                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();

                                            control.ID = "uc" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                            hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        dtaddressfields.Rows.RemoveAt(0);
                                        FieldId++;

                                    }

                                    AddressTableRows = 0;
                                    dTAdd.Controls.Add(dTAddRow);

                                }
                                else
                                {
                                    break;
                                }


                            }
                            this.dTCell.Controls.Add(dTAdd);




                            dtFields.Rows.RemoveAt(0);
                            this.dTRow.Controls.Add(this.dTCell);
                            if (tCells == 0)
                            {
                                this.dTRow.Controls.Add(this.dTCell2);
                            }

                        }


                    }

                    this.dTable.Controls.Add(dTRow);
                }
                else
                {
                    break;
                }

            }


            if (SessionTable.Length > 1)
            {
                int SessionTableId = 1;
                for (int i = 1; i < SessionTable.Length; i++)
                {


                    this.dTRow = new HtmlTableRow();

                    for (tCells = 0; tCells < 2; tCells++)
                    {
                        string sessionTab = "Address" + SessionTableId.ToString();
                        DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                        if (myArrayDataFromSession != null)
                        {
                            this.dTCell = new HtmlTableCell();
                            this.dTCell2 = new HtmlTableCell();
                            dTCell2.Attributes.Add("class", "bevel_verline");

                            this.dTAdd = new HtmlTable();
                            this.dTAdd.CellPadding = 2;
                            this.dTAdd.CellSpacing = 0;
                            this.dTAdd.Border = 0;
                            this.dTAdd.Width = "100%";
                            //dTCell.Attributes.Add("class", "darkblue_content");
                            this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";

                            int AddressTableRows = 0;
                            for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                            {

                                this.dTAddRow = new HtmlTableRow();

                                this.dTAddCell = new HtmlTableCell();
                                this.dTAddCell1 = new HtmlTableCell();
                                this.dTAddCell2 = new HtmlTableCell();
                                this.dTAddCell.Align = "right";
                                dTAddCell.Attributes.Add("class", "student_grid");
                                if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                {
                                    this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                    this.dTAddCell1.InnerText = " : ";
                                }
                                dTAddCell.Align = "left";
                                dTAddCell2.Align = "left";
                                dTAddCell.VAlign = "top";
                                dTAddCell1.VAlign = "top";
                                dTAddCell2.VAlign = "top";
                                dTAddCell.Attributes.Add("class", "width45");

                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                {
                                    TextBox txt = new TextBox();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    txt.CssClass = "textbox2";
                                    txt.ID = "txt" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(txt);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                {
                                    CheckBoxList chk = new CheckBoxList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    chk.ID = "chk" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    chk.Items.Add("Same as Student's Home Address");
                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                    this.dTAddCell2.Controls.Add(chk);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                {
                                    RadioButtonList rdb = new RadioButtonList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    rdb.ID = "rdb" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                    this.dTAddCell2.Controls.Add(rdb);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                {
                                    DropDownList ddl = new DropDownList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    ddl.ID = "ddl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    ddl.CssClass = "dropdown2";
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                    {
                                        // categoryfields.populateState(ref ddl);
                                        StuLIstCont.populateState(ref ddl);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                    {
                                        // schoolcategory.PopulateContactRelationship(ref ddl);
                                        StuLIstCont.PopulateContactRelationship(ref ddl);
                                    }
                                    this.dTAddCell2.Controls.Add(ddl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                {
                                    Label lbl = new Label();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    lbl.ID = "lbl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(lbl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                //***********01/05/2010**********
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                {
                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    control.ID = "uc" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(control);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                this.dTAddRow.Controls.Add(dTAddCell);
                                this.dTAddRow.Controls.Add(dTAddCell1);
                                this.dTAddRow.Controls.Add(dTAddCell2);
                                // myArrayDataFromSession.Rows.RemoveAt(0);
                                FieldId++;

                                // }

                                AddressTableRows = 0;
                                dTAdd.Controls.Add(dTAddRow);

                            }


                            this.dTCell.Controls.Add(dTAdd);
                            this.dTRow.Controls.Add(this.dTCell);
                            if (tCells == 0)
                            {
                                this.dTRow.Controls.Add(this.dTCell2);
                            }

                            this.dTable.Controls.Add(dTRow);


                        }

                        SessionTableId++;
                        // }
                    }

                }


            }
            else
            {

                //StudentEditInfoBL stEditInfo = new StudentEditInfoBL();
                //StudentBL stBL = new StudentBL();
                OpenSISWCFServiceStudentEditClient stEditInfo = new OpenSISWCFServiceStudentEditClient();
                IopenSISServiceStudentClient stBL = new IopenSISServiceStudentClient();
                //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                //  stBL.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                CatId = Convert.ToInt32(hdnCatId.Value);
                int StudentID = Convert.ToInt32(hdnStudentId.Value);

                int HomeFieldId = 152;


                int CheckCell = 0;
                int RowNo = 0;
                DataTable dtAddField = stEditInfo.GetAdditionalAddressContactSetStudentEdit(StudentID, SchoolID);
                int mod = dtAddField.Rows.Count % 2;
                if (mod == 0)
                {
                    RowNo = dtAddField.Rows.Count / 2;
                }
                else
                {
                    RowNo = Convert.ToInt32(dtAddField.Rows.Count / 2) + 1;

                }
                for (int i = 0; i < RowNo; i++)
                {


                    this.dTRow = new HtmlTableRow();

                    for (tCells = 0; tCells < 2; tCells++)
                    {

                        DataTable myArrayDataFromSession = stBL.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
                        if (CheckCell == dtAddField.Rows.Count)
                        {
                            myArrayDataFromSession = null;
                        }

                        if (myArrayDataFromSession != null)
                        {
                            this.dTCell = new HtmlTableCell();
                            this.dTCell2 = new HtmlTableCell();
                            dTCell2.Attributes.Add("class", "bevel_verline");

                            this.dTAdd = new HtmlTable();
                            this.dTAdd.CellPadding = 2;
                            this.dTAdd.CellSpacing = 0;
                            this.dTAdd.Border = 0;
                            this.dTAdd.Width = "100%";
                            //dTCell.Attributes.Add("class", "darkblue_content");


                            //string origtext = "Additional Contact";
                            //string trantext = DTL.Translate(origtext, "en", langto);



                            this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtAddField.Rows[CheckCell]["ContactName"].ToString() + "</div><div class=clear_m></div>";

                            int AddressTableRows = 0;
                            for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                            {

                                this.dTAddRow = new HtmlTableRow();

                                this.dTAddCell = new HtmlTableCell();
                                this.dTAddCell1 = new HtmlTableCell();
                                this.dTAddCell2 = new HtmlTableCell();
                                this.dTAddCell.Align = "right";
                                dTAddCell.Attributes.Add("class", "student_grid");
                                if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                {
                                    this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                    this.dTAddCell1.InnerText = " : ";
                                }
                                dTAddCell.Align = "left";
                                dTAddCell2.Align = "left";
                                dTAddCell.VAlign = "top";
                                dTAddCell1.VAlign = "top";
                                dTAddCell2.VAlign = "top";
                                dTAddCell.Attributes.Add("class", "width45");

                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                {
                                    TextBox txt = new TextBox();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    txt.CssClass = "textbox2";
                                    txt.ID = "txt" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(txt);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                {
                                    CheckBoxList chk = new CheckBoxList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    chk.ID = "chk" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    chk.Items.Add("Same as Student's Home Address");
                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                    this.dTAddCell2.Controls.Add(chk);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                {
                                    RadioButtonList rdb = new RadioButtonList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    rdb.ID = "rdb" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                    this.dTAddCell2.Controls.Add(rdb);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                {
                                    DropDownList ddl = new DropDownList();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    ddl.ID = "ddl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    ddl.CssClass = "dropdown2";
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                    {
                                        //categoryfields.populateState(ref ddl);
                                        StuLIstCont.populateState(ref ddl);
                                    }
                                    if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                    {
                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                        StuLIstCont.PopulateContactRelationship(ref ddl);
                                    }
                                    this.dTAddCell2.Controls.Add(ddl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                {
                                    Label lbl = new Label();
                                    HiddenField hdnFieldAddr = new HiddenField();
                                    lbl.ID = "lbl" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(lbl);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                //*************01/05/2010*************
                                if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                {
                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                    HiddenField hdnFieldAddr = new HiddenField();

                                    control.ID = "uc" + FieldId;
                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                    hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                    this.dTAddCell2.Controls.Add(control);
                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                }
                                this.dTAddRow.Controls.Add(dTAddCell);
                                this.dTAddRow.Controls.Add(dTAddCell1);
                                this.dTAddRow.Controls.Add(dTAddCell2);
                                // myArrayDataFromSession.Rows.RemoveAt(0);
                                FieldId++;

                                // }

                                AddressTableRows = 0;
                                dTAdd.Controls.Add(dTAddRow);

                            }


                            this.dTCell.Controls.Add(dTAdd);
                            this.dTRow.Controls.Add(this.dTCell);
                            if (tCells == 0)
                            {
                                this.dTRow.Controls.Add(this.dTCell2);
                            }

                            this.dTable.Controls.Add(dTRow);

                            CheckCell++;
                        }


                        // }
                    }

                }

            }
            phAllFieldHolder.Controls.Add(dTable);

            //else
            //{


            //    //hdnCatId.Value = dt.Rows[0][0].ToString();
            //    hdnInitialCatId.Value = hdnCatId.Value;
            //    btnImmuAdd.Visible = true;
            //    ibtnAlertAdd.Visible = true;
            //    ibtnNursevisitAdd.Visible = true;
            //    GVImmunization.Visible = true;
            //    //GVMedicalAlert.Visible = true;
            //    GVNurseVisitRec.Visible = true;
            //    ibtnVace.Visible = true;
            //    rptrVaceField.Visible = true;
            //    rptMedicalInfo.Visible = true;
            //    TMInfo.Visible = true;
            //    StudentInfoBL StdInfo = new StudentInfoBL();
            //    StudentEditInfoBL StdEditInfo = new StudentEditInfoBL();
            //   // StudentBL schoolcategory = new StudentBL();
            //    ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //    StdInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
            //    StdInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);
            //    StdEditInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
            //    StdEditInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);

            //    DataTable dtMedicalInfo = new DataTable();
            //    dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //    if (dtMedicalInfo.Rows.Count > 0)
            //    {
            //        rptMedicalInfo.DataSource = dtMedicalInfo;
            //        rptMedicalInfo.DataBind();
            //    }


            //    DataTable dtImmu = StdInfo.GetImmunizationFieldValue();
            //    DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
            //    if (dtImmu.Rows.Count > 0 && SessiondtImmu == null)
            //    {
            //        Session.Add("ImmuTable", dtImmu);
            //        GVImmunization.DataSource = dtImmu;
            //        GVImmunization.DataBind();
            //    }
            //    else
            //    {
            //        GVImmunization.DataSource = SessiondtImmu;
            //        GVImmunization.DataBind();
            //    }

            //    DataTable dtAlert = StdInfo.GetMedicalAlertFieldValue();
            //    DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
            //    if (dtAlert.Rows.Count > 0 && SessiondtAlert == null)
            //    {
            //        Session.Add("AlertTable", dtAlert);
            //        GVMedicalAlert.DataSource = dtAlert;
            //        GVMedicalAlert.DataBind();
            //    }
            //    else
            //    {
            //        GVMedicalAlert.DataSource = SessiondtAlert;
            //        GVMedicalAlert.DataBind();
            //    }

            //    DataTable dtNurseVisit = StdInfo.GetNurseVisitFieldValue();
            //    DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
            //    if (dtNurseVisit.Rows.Count > 0 && SessiondtNurseVisit == null)
            //    {
            //        Session.Add("NurseVisitTable", dtNurseVisit);
            //        GVNurseVisitRec.DataSource = dtNurseVisit;
            //        GVNurseVisitRec.DataBind();
            //    }
            //    else
            //    {
            //        GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            //        GVNurseVisitRec.DataBind();
            //    }

            //    DataTable dtMedicalInfovalue = StdEditInfo.PopulateMedicalInfoValue();
            //    DataTable MedicalInfoDataFromSession = (DataTable)Session["MedicalInfo"];

            //    if (dtNurseVisit.Rows.Count > 0 && MedicalInfoDataFromSession == null)
            //    {
            //        Session.Add("MedicalInfo", dtMedicalInfovalue);
            //        PopulateMedicalInfoFieldData();
            //    }
            //    else
            //    {
            //        PopulateMedicalInfoFieldData();
            //    }

            //    DataTable dtVaccination = PopulateVacciGrid();
            //    GVVccination.DataSource = dtVaccination;
            //    GVVccination.DataBind();
            //    // lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";



            //}

            //}
            //catch
            //{

            //}
        }
        else
        {


            //tblProgram.Visible = false;
            //btnImmuAdd.Visible = false;
            //ibtnAlertAdd.Visible = false;
            //ibtnNursevisitAdd.Visible = false;
            //GVImmunization.Visible = false;
            ////GVMedicalAlert.Visible = false;
            //GVNurseVisitRec.Visible = false;
            //ibtnVace.Visible = false;
            //rptrVaceField.Visible = false;
            //rptMedicalInfo.Visible = false;
            //TMInfo.Visible = false;

            //tblSchEnrInfo.Visible = false;
            //rptrSchlInfo.Visible = false;
            //gvEnrInfo.Visible = false;

            tblProgram.Visible = false;
            btnImmuAdd.Visible = false;
            ibtnAlertAdd.Visible = false;
            ibtnNursevisitAdd.Visible = false;
            GVImmunization.Visible = false;
            GVMedicalAlert.Visible = false;
            GVNurseVisitRec.Visible = false;
            ibtnVace.Visible = false;
            rptrVaceField.Visible = false;
            rptMedicalInfo.Visible = false;
            TMInfo.Visible = false;

            tblSchEnrInfo.Visible = false;
            rptrSchlInfo.Visible = false;
            gvEnrInfo.Visible = false;

            if (hdnCatId.Value.ToString() != "5")
            {
                // AllMedicalDataChange();
                if (hdnCatId.Value.ToString() != "4")
                {
                    //tblSchEnrInfo.Visible = false;
                    //rptrSchlInfo.Visible = false;
                    //gvEnrInfo.Visible = false;
                    //StudentBL stBL = new StudentBL();

                    IopenSISServiceStudentClient stBL = new IopenSISServiceStudentClient();

                    // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    SchoolID = Convert.ToInt32(Session["SchoolID"]);

                    if (hdnCatId.Value.ToString() != "8")
                    {

                        int Count = dTable.Rows.Count;

                        for (int k = Count - 1; k >= 0; k--)
                        {

                            this.dTable.Rows.RemoveAt(k);

                        }

                        this.dTable.CellPadding = 2;
                        this.dTable.CellSpacing = 0;
                        this.dTable.Border = 0;
                        this.dTable.Width = "100%";
                        this.dTable.Align = "center";
                        //this.dTable.Attributes.Add("class", "darkblue_content");

                        int tRows;
                        int tCells = 2;
                        int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);

                        int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
                        if (tCellsmod != 0)
                        {
                            tCellsquotient = tCellsquotient + 1;
                            int j = dt.Rows.Count;

                            DataRow dr = dt.NewRow();
                            dt.Rows.Add(dr);

                        }
                        //ibtnAdd.Visible = false;

                        this.dTRow = new HtmlTableRow();
                        this.dTCell = new HtmlTableCell();
                        this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                        this.dTCell.ColSpan = 6;
                        this.dTRow.Cells.Add(dTCell);
                        this.dTable.Rows.Insert(0, dTRow);

                        for (tRows = 0; tRows < tCellsquotient; tRows++)
                        {
                            tRows = 0;
                            if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
                            {

                                this.dTRow = new HtmlTableRow();
                                for (tCells = 0; tCells < 2; tCells++)
                                {

                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell1 = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    if (dt.Rows[tRows]["FieldName"].ToString() != "")
                                    {
                                        this.dTCell.InnerHtml = "<div class='blue_bold'>" + dt.Rows[tRows]["FieldName"].ToString() + "</div>"; 
                                        //this.dTCell.InnerHtml = "<span class='blue_bold'>" + dt.Rows[tRows]["FieldName"].ToString() + "</span>";
                                        this.dTCell1.InnerText = ":";
                                    }
                                    dTCell.VAlign = "top";
                                    dTCell1.VAlign = "top";
                                    dTCell2.VAlign = "top";
                                    int FieldidPopulate = 0;
                                    if (dt.Rows[tRows]["FieldId"].ToString() != "")
                                    {
                                        FieldidPopulate = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                    }
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "1")
                                    {
                                        TextBox txt = new TextBox();
                                        HiddenField hdnFieldId = new HiddenField();
                                        txt.CssClass = "textbox2";
                                        txt.ID = "txt" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        this.dTCell2.Controls.Add(txt);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "2")
                                    {
                                        CheckBoxList chk = new CheckBoxList();
                                        HiddenField hdnFieldId = new HiddenField();
                                        chk.ID = "chk" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        chk.RepeatDirection = RepeatDirection.Horizontal;
                                        if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                        {
                                            //categoryfields.populatedynamicrchk(ref chk);
                                            StuLIstCont.populatedynamicrchk(ref chk, FieldidPopulate);
                                        }
                                        this.dTCell2.Controls.Add(chk);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "3")
                                    {
                                        RadioButtonList rdb = new RadioButtonList();
                                        HiddenField hdnFieldId = new HiddenField();
                                        rdb.ID = "rdb" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                                        if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                        {
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 10)
                                            {
                                                //categoryfields.PopulateGender(ref rdb);
                                                StuLIstCont.PopulateGender(ref rdb);
                                            }
                                        }
                                        if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                        {
                                            //categoryfields.populatedynamicrbtn(ref rdb);
                                            StuLIstCont.populatedynamicrbtn(ref rdb, FieldidPopulate);
                                        }
                                        this.dTCell2.Controls.Add(rdb);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "4")
                                    {
                                        DropDownList ddl = new DropDownList();
                                        HiddenField hdnFieldId = new HiddenField();
                                        ddl.ID = "ddl" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        ddl.CssClass = "dropdown2";
                                        if (dt.Rows[tRows]["Default_Custom"].ToString() == "D")
                                        {
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                            {
                                                //categoryfields.populateEthnicity(ref ddl);
                                                //********18/05/2010*****
                                                StuLIstCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                            }
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                            {
                                                //categoryfields.populateLanguage(ref ddl);
                                                StuLIstCont.populateLanguage(ref ddl);
                                            }
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                            {
                                                //categoryfields.populateCountry(ref ddl);
                                                StuLIstCont.populateCountry(ref ddl);
                                            }
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                            {
                                                // vmlBL.populateCountry(ref ddl);
                                                //categoryfields.PopulateEnrollCdn(ref ddl);
                                                StuLIstCont.PopulateEnrollCdn(ref ddl);
                                            }
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                            {

                                                //stBL.populatecalender(ref ddl);
                                                StuLIstCont.populatecalender(ref ddl, SchoolID);
                                            }

                                            //****************06/02/2010***********
                                            if (Convert.ToInt32(dt.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                            {


                                                StuListCont.populateReligion(ref ddl);
                                            }
                                        }
                                        if (dt.Rows[tRows]["Default_Custom"].ToString() == "C")
                                        {
                                            //categoryfields.populatedynamicddl(ref ddl);
                                            StuLIstCont.populatedynamicddl(ref ddl, FieldidPopulate);
                                        }
                                        this.dTCell2.Controls.Add(ddl);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "5")
                                    {
                                        Label lbl = new Label();
                                        HiddenField hdnFieldId = new HiddenField();
                                        lbl.ID = "lbl" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        this.dTCell2.Controls.Add(lbl);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }
                                    //***********01/05/2010***********
                                    if (dt.Rows[tRows]["FieldType"].ToString() == "6")
                                    {
                                        var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                        HiddenField hdnFieldId = new HiddenField();
                                        control.ID = "uc" + FieldId;
                                        hdnFieldId.ID = "hdn" + FieldId;
                                        hdnFieldId.Value = dt.Rows[tRows]["FieldId"].ToString() + "_" + dt.Rows[tRows]["Default_Custom"].ToString();
                                        this.dTCell2.Controls.Add(control);
                                        this.dTCell2.Controls.Add(hdnFieldId);
                                    }



                                    FieldId++;

                                    this.dTRow.Controls.Add(this.dTCell);
                                    this.dTRow.Controls.Add(this.dTCell1);
                                    this.dTRow.Controls.Add(this.dTCell2);
                                    dt.Rows.RemoveAt(0);
                                    tRows = 0;
                                }
                                this.dTable.Controls.Add(dTRow);

                            }
                            else
                            {
                                break;
                            }
                        }


                        this.dTRow = new HtmlTableRow();
                        this.dTCell = new HtmlTableCell();
                        this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                        this.dTCell.ColSpan = 6;
                        this.dTRow.Cells.Add(dTCell);
                        this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);



                        phAllFieldHolder.Controls.Add(dTable);
                    }
                    else
                    {
                        //Special and gifted in selcted node change
                        tblSchEnrInfo.Visible = false;
                        TMInfo.Visible = false;
                        tblProgram.Visible = true;
                        //ibtnAdd.Visible = false;



                    }
                }
                else
                {
                    //enrollment in selected node change
                    //ibtnAdd.Visible = false;
                    tblProgram.Visible = false;
                    tblSchEnrInfo.Visible = true;
                    rptrSchlInfo.Visible = true;
                    gvEnrInfo.Visible = true;
                    int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
                    DataTable dtschlinfo = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());

                    rptrSchlInfo.DataSource = dtschlinfo;
                    rptrSchlInfo.DataBind();
                    PopulateSchoolFieldData();



                    DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                    if (SessiondtEnrol != null)
                    {
                        gvEnrInfo.DataSource = SessiondtEnrol;
                        gvEnrInfo.DataBind();
                    }
                    else
                    {
                        DataTable dtenrol = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);

                        if (dtenrol.Rows.Count > 0)
                        {
                            gvEnrInfo.DataSource = dtenrol;
                            gvEnrInfo.DataBind();

                            //**********222222
                            Session.Add("Enroltable", dtenrol);

                        }
                        else
                        {
                            //**************26/05/10
                            //DataTable dtEnrol = new DataTable();
                            //dtEnrol.Columns.Add("Std_Enr_Id");
                            //dtEnrol.Columns.Add("Enr_Start_Date");
                            //dtEnrol.Columns.Add("Enr_End_Date");
                            //dtEnrol.Columns.Add("enrollname");
                            //dtEnrol.Columns.Add("Exit_Reason");
                            //dtEnrol.Columns.Add("Start_Condition");
                            //dtEnrol.Columns.Add("Enr_Code_Id");

                            //DataRow dr = dtEnrol.NewRow();
                            //dtEnrol.Rows.Add(dr);
                            //gvEnrInfo.DataSource = dtEnrol;
                            //gvEnrInfo.DataBind();

                            //***************222222
                            ////Session.Add("Enroltable", dtEnrol);
                        }
                    }
                }
            }
            else
            {

                // hdnCatId.Value = dt.Rows[0][0].ToString();
                //ibtnAdd.Visible = false;
                hdnInitialCatId.Value = hdnCatId.Value;
                btnImmuAdd.Visible = true;
                ibtnAlertAdd.Visible = true;
                ibtnNursevisitAdd.Visible = true;
                GVImmunization.Visible = true;
                GVMedicalAlert.Visible = true;
                GVNurseVisitRec.Visible = true;
                ibtnVace.Visible = true;
                rptrVaceField.Visible = true;
                rptMedicalInfo.Visible = true;
                TMInfo.Visible = true;
                //StudentInfoBL StdInfo = new StudentInfoBL();
                //StudentEditInfoBL StdEditInfo = new StudentEditInfoBL();
                // StudentBL schoolcategory = new StudentBL();

                OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
                OpenSISWCFServiceStudentEditClient StdEditInfo = new OpenSISWCFServiceStudentEditClient();


                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int StudentID = Convert.ToInt32(hdnStudentId.Value);
                //StdEditInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                //StdEditInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);

                DataTable dtMedicalInfo = new DataTable();
                dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                if (dtMedicalInfo.Rows.Count > 0)
                {
                    rptMedicalInfo.DataSource = dtMedicalInfo;
                    rptMedicalInfo.DataBind();
                }


                DataTable dtImmu = StdInfo.GetImmunizationFieldValue(SchoolID, StudentID);
                DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                if (dtImmu.Rows.Count > 0 && SessiondtImmu == null)
                {
                    Session.Add("ImmuTable", dtImmu);
                    GVImmunization.DataSource = dtImmu;
                    GVImmunization.DataBind();
                }
                else
                {
                    GVImmunization.DataSource = SessiondtImmu;
                    GVImmunization.DataBind();
                }

                DataTable dtAlert = StdInfo.GetMedicalAlertFieldValue(StudentID);
                DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                if (dtAlert.Rows.Count > 0 && SessiondtAlert == null)
                {
                    Session.Add("AlertTable", dtAlert);
                    GVMedicalAlert.DataSource = dtAlert;
                    GVMedicalAlert.DataBind();
                }
                else
                {
                    GVMedicalAlert.DataSource = SessiondtAlert;
                    GVMedicalAlert.DataBind();
                }

                DataTable dtNurseVisit = StdInfo.GetNurseVisitFieldValue(SchoolID, StudentID);
                DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                if (dtNurseVisit.Rows.Count > 0 && SessiondtNurseVisit == null)
                {
                    Session.Add("NurseVisitTable", dtNurseVisit);
                    GVNurseVisitRec.DataSource = dtNurseVisit;
                    GVNurseVisitRec.DataBind();
                }
                else
                {
                    GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                    GVNurseVisitRec.DataBind();
                }

                DataTable dtMedicalInfovalue = StdEditInfo.PopulateMedicalInfoValueStudentEdit(StudentID, SchoolID);
                DataTable MedicalInfoDataFromSession = (DataTable)Session["MedicalInfo"];

                if (dtMedicalInfovalue.Rows.Count > 0 && MedicalInfoDataFromSession == null)
                {
                    Session.Add("MedicalInfo", dtMedicalInfovalue);
                    PopulateMedicalInfoFieldData();
                }
                else
                {
                    PopulateMedicalInfoFieldData();
                }

               



            }
        }

        if (Treepos == 0)
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = false;
            btnNext.Visible = true;

        }
        else if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }

        //}
        //catch
        //{

        //}
    }

    protected void PopulateNextFields()
    {

        try
        {
            //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            //StudentSetupBL StSuBL = new StudentSetupBL();
            //StudentBL STBL = new StudentBL();
            int FieldIdPopulate = 0;

            StudentListControl StuListCont = new StudentListControl();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
            IopenSISServiceStudentClient STBL = new IopenSISServiceStudentClient();

            int CatId = Convert.ToInt32(hdnCatId.Value);
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            //TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected =true;


            DataTable dt = STBL.GetNextCategoryStudentBusiness(SchoolID, CatId);
            if (dt.Rows[0][0].ToString() == "1")
            {

                divPhotoUpload.Style.Add("Display", "block");
                divOuter.Style.Add("Display", "block");
            }
            else
            {
                divPhotoUpload.Style.Add("Display", "none");
                divOuter.Style.Add("Display", "none");
            }
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                string t = tn.Value.Split(",".ToCharArray())[0];
                if (t == dt.Rows[0][0].ToString())
                {

                    tn.Selected = true;

                }

            }
            string CatName = TreeView1.SelectedNode.Text.ToString();
            int FieldId = 0;
            if (dt.Rows.Count > 0)
            {

                if (dt.Rows[0][0].ToString() != "3")
                {

                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;

                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;

                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;
                    tblProgram.Visible = false;




                    if (dt.Rows[0][0].ToString() != "5")
                    {
                        if (dt.Rows[0][0].ToString() != "4")
                        {
                            //enrollment
                            tblSchEnrInfo.Visible = false;
                            rptrSchlInfo.Visible = false;
                            gvEnrInfo.Visible = false;
                            //enrollment
                            //StudentBL schoolcategory = new StudentBL();
                            if (dt.Rows[0][0].ToString() != "8")
                            {
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();

                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;
                                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                // ibtnAdd.Visible = false;

                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";
                                //this.dTable.Attributes.Add("class", "darkblue_content");
                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                                int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    DataRow dr = dtFields.NewRow();
                                    dtFields.Rows.Add(dr);

                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);

                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                                    {

                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {

                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();
                                            dTCell.Attributes.Add("class", "student_grid");


                                            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }
                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";

                                            if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                FieldIdPopulate = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.CssClass = "textbox2";
                                                txt.ID = "txt" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicrchk(ref chk);
                                                    StuListCont.populatedynamicrchk(ref chk, FieldIdPopulate);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        //categoryfields.PopulateGender(ref rdb);
                                                        StuListCont.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicrbtn(ref rdb);
                                                    StuListCont.populatedynamicrbtn(ref rdb, FieldIdPopulate);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                ddl.CssClass = "dropdown2";
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        //categoryfields.populateEthnicity(ref ddl);
                                                        //**********18/05/2010*************
                                                        StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        //categoryfields.populateLanguage(ref ddl);
                                                        StuListCont.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        // categoryfields.populateCountry(ref ddl);
                                                        StuListCont.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        //categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StuListCont.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        //STBL.populatecalender(ref ddl);
                                                        StuListCont.populatecalender(ref ddl, SchoolID);
                                                    }
                                                    //****************06/02/2010***********
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {


                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicddl(ref ddl);
                                                    StuListCont.populatedynamicddl(ref ddl, FieldIdPopulate);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            //***********01/05/2010***************
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
                                            {
                                                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                HiddenField hdnFieldId = new HiddenField();
                                                control.ID = "uc" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dtFields.Rows.RemoveAt(0);
                                            tRows = 0;
                                            FieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);
                                        // FieldId++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            else
                            {
                                //Special and gifted in next
                                //StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                //ibtnAdd.Visible = false;
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;


                            }
                        }
                        else
                        {
                            //enrollment in next fields
                            hdnCatId.Value = dt.Rows[0][0].ToString();
                            CatId = Convert.ToInt32(hdnCatId.Value);
                            tblSchEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            gvEnrInfo.Visible = true;
                            hdnInitialCatId.Value = hdnCatId.Value;
                            int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
                            DataTable dtschlinfo = STBL.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());

                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();
                            PopulateSchoolFieldData();

                            DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                            if (SessiondtEnrol != null)
                            {
                                gvEnrInfo.DataSource = SessiondtEnrol;
                                gvEnrInfo.DataBind();
                            }
                            else
                            {
                                DataTable dtenrol = STBL.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);

                                if (dtenrol.Rows.Count > 0)
                                {
                                    gvEnrInfo.DataSource = dtenrol;
                                    gvEnrInfo.DataBind();
                                    //******222222222222
                                    Session.Add("Enroltable", dtenrol);
                                }
                                else
                                {
                                    DataTable dtEnrol = new DataTable();
                                    dtEnrol.Columns.Add("Std_Enr_Id");
                                    dtEnrol.Columns.Add("Enr_Start_Date");
                                    dtEnrol.Columns.Add("Enr_End_Date");
                                    dtEnrol.Columns.Add("enrollname");
                                    dtEnrol.Columns.Add("Exit_Reason");
                                    dtEnrol.Columns.Add("Start_Condition");
                                    dtEnrol.Columns.Add("Enr_Code_Id");

                                    DataRow dr = dtEnrol.NewRow();
                                    dtEnrol.Rows.Add(dr);
                                    gvEnrInfo.DataSource = dtEnrol;
                                    gvEnrInfo.DataBind();

                                    //********2222222222222
                                    Session.Add("Enroltable", dtEnrol);
                                }
                            }

                        }
                    }
                    else
                    {
                        //enrollment 
                        tblSchEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        gvEnrInfo.Visible = false;
                        //enrollment

                        hdnCatId.Value = dt.Rows[0][0].ToString();
                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;
                        //StudentInfoBL StdInfo = new StudentInfoBL();
                        //StudentEditInfoBL StdEditInfo = new StudentEditInfoBL();
                        //StudentBL schoolcategory = new StudentBL();


                        OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
                        OpenSISWCFServiceStudentEditClient StdEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();



                        // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);
                        //StdEditInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        //StdEditInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);

                        DataTable dtMedicalInfo = new DataTable();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        if (dtMedicalInfo.Rows.Count > 0)
                        {
                            rptMedicalInfo.DataSource = dtMedicalInfo;
                            rptMedicalInfo.DataBind();
                        }


                        DataTable dtImmu = StdInfo.GetImmunizationFieldValue(SchoolID, StudentID);
                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (dtImmu.Rows.Count > 0 && SessiondtImmu == null)
                        {
                            Session.Add("ImmuTable", dtImmu);
                            GVImmunization.DataSource = dtImmu;
                            GVImmunization.DataBind();
                        }
                        else
                        {
                            GVImmunization.DataSource = SessiondtImmu;
                            GVImmunization.DataBind();
                        }

                        DataTable dtAlert = StdInfo.GetMedicalAlertFieldValue(StudentID);
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (dtAlert.Rows.Count > 0 && SessiondtAlert == null)
                        {
                            Session.Add("AlertTable", dtAlert);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            GVMedicalAlert.DataSource = SessiondtAlert;
                            GVMedicalAlert.DataBind();
                        }

                        DataTable dtNurseVisit = StdInfo.GetNurseVisitFieldValue(SchoolID, StudentID);
                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (dtNurseVisit.Rows.Count > 0 && SessiondtNurseVisit == null)
                        {
                            Session.Add("NurseVisitTable", dtNurseVisit);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }

                        DataTable dtMedicalInfovalue = StdEditInfo.PopulateMedicalInfoValueStudentEdit(StudentID, SchoolID);
                        DataTable MedicalInfoDataFromSession = (DataTable)Session["MedicalInfo"];

                        if (dtMedicalInfovalue.Rows.Count > 0 && MedicalInfoDataFromSession == null)
                        {
                            Session.Add("MedicalInfo", dtMedicalInfovalue);
                            PopulateMedicalInfoFieldData();
                        }
                        else
                        {
                            PopulateMedicalInfoFieldData();
                        }



                       


                        // lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";


                    }

                }

                else
                {
                    //enrollment 
                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;
                    //enrollment
                    tblProgram.Visible = false;
                    //StudentBL schoolcategory = new StudentBL();

                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();

                    hdnCatId.Value = dt.Rows[0][0].ToString();
                    hdnInitialCatId.Value = hdnCatId.Value;
                    CatId = Convert.ToInt32(hdnCatId.Value);
                    // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    // ibtnAdd.Visible = true;



                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;

                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");

                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);

                    }

                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        int L = 0;

                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {
                            this.dTRow = new HtmlTableRow();


                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");
                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";

                                //dTCell.Attributes.Add("class", "darkblue_content");


                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";


                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                    FieldIdPopulate = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    // schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);

                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldIdPopulate, Session["MLUICulture"].ToString());

                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;

                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);

                                    }


                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();

                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {

                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();

                                                dTAddCell.Attributes.Add("class", "student_grid");
                                                this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                //dTCell.Align = "right";
                                                this.dTAddCell1.InnerText = " : ";
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    txt.CssClass = "textbox2";
                                                    txt.ID = "txt" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();
                                                    chk.ID = "chk" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    chk.Items.Add("Same as Student's Home Address");
                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    rdb.ID = "rdb" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    ddl.ID = "ddl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //categoryfields.populateState(ref ddl);
                                                        StuListCont.populateState(ref ddl);
                                                    }
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StuListCont.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    lbl.ID = "lbl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //****************01/05/2010*************

                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    control.ID = "uc" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }


                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);

                                                dtaddressfields.Rows.RemoveAt(0);
                                                FieldId++;

                                            }



                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);


                                        }
                                        else
                                        {
                                            break;
                                        }

                                    }

                                    this.dTCell.Controls.Add(dTAdd);
                                    dtFields.Rows.RemoveAt(0);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }


                                }
                                this.dTable.Controls.Add(dTRow);
                            }

                        }
                        else
                        {
                            break;
                        }
                    }


                    string[] SessionTable = AddTableList.Split(';');
                    if (SessionTable.Length > 1)
                    {
                        int SessionTableId = 1;
                        for (int i = 1; i < SessionTable.Length; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                string sessionTab = "Address" + SessionTableId.ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");
                                    this.dTAdd = new HtmlTable();
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");

                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {

                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            chk.Items.Add("Same as Student's Home Address");
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "4" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "13" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "24" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                            {
                                                // categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }

                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                //categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StuListCont.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //**********01/05/2010*******************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[AddressTableRows]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }

                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        FieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                    this.dTable.Controls.Add(dTRow);

                                }

                                SessionTableId++;
                                // }
                            }

                        }
                    }
                    else
                    {

                        //enrollment
                        tblSchEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        gvEnrInfo.Visible = false;
                        tblProgram.Visible = false;
                        //enrollment

                        //StudentEditInfoBL stEditInfo = new StudentEditInfoBL();
                        //StudentBL stBL = new StudentBL();


                        OpenSISWCFServiceStudentEditClient stEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient stBL = new IopenSISServiceStudentClient();

                        //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        //stBL.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);

                        int HomeFieldId = 152;

                        int CheckCell = 0;
                        int RowNo = 0;
                        DataTable dtAddField = stEditInfo.GetAdditionalAddressContactSetStudentEdit(StudentID, SchoolID);
                        int mod = dtAddField.Rows.Count % 2;
                        if (mod == 0)
                        {
                            RowNo = dtAddField.Rows.Count / 2;
                        }
                        else
                        {
                            RowNo = Convert.ToInt32(dtAddField.Rows.Count / 2) + 1;

                        }
                        for (int i = 0; i < RowNo; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                DataTable myArrayDataFromSession = stBL.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
                                if (CheckCell == dtAddField.Rows.Count)
                                {
                                    myArrayDataFromSession = null;
                                }

                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");

                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    this.dTAdd.Width = "100%";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtAddField.Rows[CheckCell]["ContactName"].ToString() + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            chk.Items.Add("Same as Student's Home Address");
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                // categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                // schoolcategory.PopulateContactRelationship(ref ddl);
                                                StuListCont.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //**********01/05/2010****************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        FieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                    this.dTable.Controls.Add(dTRow);
                                    CheckCell++;

                                }


                                // }
                            }

                        }
                    }

                    phAllFieldHolder.Controls.Add(dTable);

                }


                btnPrev.Visible = true;
                if (dt.Rows.Count == 1)
                {
                    btnUpdate.Visible = true;
                    btnNext.Visible = false;
                }
            }
        }
        catch (Exception ex)
        {
            string Error = ex.ToString();
        }

    }

    protected void PopulatePreviousFields()
    {

        try
        {
            //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            //StudentBL STBL = new StudentBL();
            //StudentSetupBL StSuBL = new StudentSetupBL();

            int FieldidPopulate = 0;


            StudentListControl StuListCont = new StudentListControl();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            IopenSISServiceStudentClient STBL = new IopenSISServiceStudentClient();
            OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();


            int CatId = Convert.ToInt32(hdnCatId.Value);
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            DataTable dt = STBL.GetPrevCategoryStudentBusiness(SchoolID, CatId);
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                string t = tn.Value.Split(",".ToCharArray())[0];
                if (t == dt.Rows[0][0].ToString())
                {

                    tn.Selected = true;

                }

            }
            int FieldId = 0;
            if (dt.Rows[0][0].ToString() == "1")
            {

                divPhotoUpload.Style.Add("Display", "block");
                divOuter.Style.Add("Display", "block");
            }
            else
            {
                divPhotoUpload.Style.Add("Display", "none");
                divOuter.Style.Add("Display", "none");
            }

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].ToString() != "3")
                {
                    btnImmuAdd.Visible = false;
                    ibtnAlertAdd.Visible = false;
                    ibtnNursevisitAdd.Visible = false;
                    GVImmunization.Visible = false;
                    GVMedicalAlert.Visible = false;
                    GVNurseVisitRec.Visible = false;
                    ibtnVace.Visible = false;
                    rptrVaceField.Visible = false;
                    rptMedicalInfo.Visible = false;
                    TMInfo.Visible = false;
                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;

                    tblProgram.Visible = false;
                    if (dt.Rows[0][0].ToString() != "5")
                    {
                        if (dt.Rows[0][0].ToString() != "4")
                        {
                            //enrollment
                            tblSchEnrInfo.Visible = false;
                            rptrSchlInfo.Visible = false;
                            gvEnrInfo.Visible = false;
                            //enrollment
                            //StudentBL schoolcategory = new StudentBL();
                            if (dt.Rows[0][0].ToString() != "8")
                            {
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();


                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                hdnInitialCatId.Value = hdnCatId.Value;
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                                SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                                string CatName = TreeView1.SelectedNode.Text.ToString();
                                DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                                //ibtnAdd.Visible = false;

                                this.dTable.CellPadding = 2;
                                this.dTable.CellSpacing = 0;
                                this.dTable.Border = 0;
                                this.dTable.Width = "100%";
                                //this.dTable.Attributes.Add("class", "darkblue_content");

                                int tRows;
                                int tCells = 2;
                                int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                                int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                                if (tCellsmod != 0)
                                {
                                    tCellsquotient = tCellsquotient + 1;
                                    int j = dtFields.Rows.Count;

                                    DataRow dr = dtFields.NewRow();
                                    dtFields.Rows.Add(dr);

                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + CatName.ToString() + "</div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(0, dTRow);

                                for (tRows = 0; tRows < tCellsquotient; tRows++)
                                {
                                    tRows = 0;
                                    if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                                    {

                                        this.dTRow = new HtmlTableRow();
                                        for (tCells = 0; tCells < 2; tCells++)
                                        {

                                            this.dTCell = new HtmlTableCell();
                                            this.dTCell1 = new HtmlTableCell();
                                            this.dTCell2 = new HtmlTableCell();
                                            dTCell.Attributes.Add("class", "student_grid");
                                            if (dtFields.Rows[tRows]["FieldName"].ToString() != "")
                                            {
                                                this.dTCell.InnerHtml = "<div class='blue_bold'>" + dtFields.Rows[tRows]["FieldName"].ToString() + "</div>";
                                                this.dTCell1.InnerText = ":";
                                            }
                                            dTCell.Align = "left";
                                            dTCell2.Align = "left";
                                            if (dtFields.Rows[tRows]["FieldId"].ToString() != "")
                                            {
                                                FieldidPopulate = Convert.ToInt32(dtFields.Rows[tRows]["FieldId"]);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "1")
                                            {
                                                TextBox txt = new TextBox();
                                                HiddenField hdnFieldId = new HiddenField();
                                                txt.CssClass = "textbox2";
                                                txt.ID = "txt" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                this.dTCell2.Controls.Add(txt);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "2")
                                            {
                                                CheckBoxList chk = new CheckBoxList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                chk.ID = "chk" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                chk.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicrchk(ref chk);
                                                    StuListCont.populatedynamicrchk(ref chk, FieldidPopulate);
                                                }
                                                this.dTCell2.Controls.Add(chk);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "3")
                                            {
                                                RadioButtonList rdb = new RadioButtonList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                rdb.ID = "rdb" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 10)
                                                    {
                                                        //categoryfields.PopulateGender(ref rdb);
                                                        StuListCont.PopulateGender(ref rdb);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    // categoryfields.populatedynamicrbtn(ref rdb);
                                                    StuListCont.populatedynamicrbtn(ref rdb, FieldidPopulate);
                                                }
                                                this.dTCell2.Controls.Add(rdb);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "4")
                                            {
                                                DropDownList ddl = new DropDownList();
                                                HiddenField hdnFieldId = new HiddenField();
                                                ddl.ID = "ddl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                ddl.CssClass = "dropdown2";
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "D")
                                                {
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 11)//ETHNICITY
                                                    {
                                                        // categoryfields.populateEthnicity(ref ddl);
                                                        //**********18/05/2010*************
                                                        StuListCont.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 15 || Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 16)//LANGUAGE
                                                    {
                                                        //categoryfields.populateLanguage(ref ddl);
                                                        StuListCont.populateLanguage(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 18)//COUNTRY
                                                    {
                                                        // categoryfields.populateCountry(ref ddl);
                                                        StuListCont.populateCountry(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 120)//START CONDITION
                                                    {
                                                        // vmlBL.populateCountry(ref ddl);
                                                        //categoryfields.PopulateEnrollCdn(ref ddl);
                                                        StuListCont.PopulateEnrollCdn(ref ddl);
                                                    }
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 110)//Calender
                                                    {

                                                        //STBL.populatecalender(ref ddl);
                                                        StuListCont.populatecalender(ref ddl, SchoolID);
                                                    }
                                                    //****************06/02/2010***********
                                                    if (Convert.ToInt32(dtFields.Rows[tRows]["FieldId"].ToString()) == 210)//Religion
                                                    {


                                                        StuListCont.populateReligion(ref ddl);
                                                    }
                                                }
                                                if (dtFields.Rows[tRows]["Default_Custom"].ToString() == "C")
                                                {
                                                    //categoryfields.populatedynamicddl(ref ddl);
                                                    StuListCont.populatedynamicddl(ref ddl, FieldidPopulate);
                                                }
                                                this.dTCell2.Controls.Add(ddl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "5")
                                            {
                                                Label lbl = new Label();
                                                HiddenField hdnFieldId = new HiddenField();
                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                // StudentBL stbl2 = new StudentBL();
                                                this.dTCell2.Controls.Add(lbl);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            //***********01/05/2010**************
                                            if (dtFields.Rows[tRows]["FieldType"].ToString() == "6")
                                            {
                                                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                HiddenField hdnFieldId = new HiddenField();
                                                control.ID = "uc" + FieldId;
                                                hdnFieldId.ID = "hdn" + FieldId;
                                                hdnFieldId.Value = dtFields.Rows[tRows]["FieldId"].ToString() + "_" + dtFields.Rows[tRows]["Default_Custom"].ToString();
                                                // StudentBL stbl2 = new StudentBL();
                                                this.dTCell2.Controls.Add(control);
                                                this.dTCell2.Controls.Add(hdnFieldId);
                                            }
                                            this.dTRow.Controls.Add(dTCell);
                                            this.dTRow.Controls.Add(dTCell1);
                                            this.dTRow.Controls.Add(dTCell2);
                                            dtFields.Rows.RemoveAt(0);
                                            tRows = 0;
                                            FieldId++;
                                        }
                                        this.dTable.Controls.Add(dTRow);

                                    }
                                    else
                                    {
                                        break;
                                    }
                                    // FieldId++;
                                }

                                this.dTRow = new HtmlTableRow();
                                this.dTCell = new HtmlTableCell();
                                this.dTCell.InnerHtml = "<div class='clear_small'></div>";
                                this.dTCell.ColSpan = 6;
                                this.dTRow.Cells.Add(dTCell);
                                this.dTable.Rows.Insert(tCellsquotient + 1, dTRow);

                                phAllFieldHolder.Controls.Add(dTable);
                            }
                            else
                            {
                                //Special and gifted in next
                                //StudentBL schoolcategory = new StudentBL();
                                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                                tblSchEnrInfo.Visible = false;
                                TMInfo.Visible = false;
                                tblProgram.Visible = true;
                                //ibtnAdd.Visible = false;
                                hdnCatId.Value = dt.Rows[0][0].ToString();
                                CatId = Convert.ToInt32(hdnCatId.Value);
                                hdnInitialCatId.Value = hdnCatId.Value;


                            }
                        }
                        else
                        {

                            //enrollment in previous fields
                            hdnCatId.Value = dt.Rows[0][0].ToString();
                            tblSchEnrInfo.Visible = true;
                            rptrSchlInfo.Visible = true;
                            gvEnrInfo.Visible = true;
                            hdnInitialCatId.Value = hdnCatId.Value;
                            CatId = Convert.ToInt32(hdnCatId.Value);
                            int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
                            DataTable dtschlinfo = STBL.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());

                            rptrSchlInfo.DataSource = dtschlinfo;
                            rptrSchlInfo.DataBind();
                            PopulateSchoolFieldData();

                            DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
                            if (SessiondtEnrol != null)
                            {
                                gvEnrInfo.DataSource = SessiondtEnrol;
                                gvEnrInfo.DataBind();
                            }
                            else
                            {
                                DataTable dtenrol = STBL.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);

                                if (dtenrol.Rows.Count > 0)
                                {
                                    gvEnrInfo.DataSource = dtenrol;
                                    gvEnrInfo.DataBind();
                                    //****2222222222
                                    Session.Add("Enroltable", dtenrol);
                                }
                                else
                                {
                                    DataTable dtEnrol = new DataTable();
                                    dtEnrol.Columns.Add("Std_Enr_Id");
                                    dtEnrol.Columns.Add("Enr_Start_Date");
                                    dtEnrol.Columns.Add("Enr_End_Date");
                                    dtEnrol.Columns.Add("enrollname");
                                    dtEnrol.Columns.Add("Exit_Reason");
                                    dtEnrol.Columns.Add("Start_Condition");
                                    dtEnrol.Columns.Add("Enr_Code_Id");

                                    DataRow dr = dtEnrol.NewRow();
                                    dtEnrol.Rows.Add(dr);
                                    gvEnrInfo.DataSource = dtEnrol;
                                    gvEnrInfo.DataBind();

                                    //********2222222222
                                    Session.Add("Enroltable", dtEnrol);
                                }
                            }

                        }
                    }
                    else
                    {
                        //enrollment
                        tblSchEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        gvEnrInfo.Visible = false;
                        //enrollment
                        hdnCatId.Value = dt.Rows[0][0].ToString();
                        hdnInitialCatId.Value = hdnCatId.Value;
                        btnImmuAdd.Visible = true;
                        ibtnAlertAdd.Visible = true;
                        ibtnNursevisitAdd.Visible = true;
                        GVImmunization.Visible = true;
                        GVMedicalAlert.Visible = true;
                        GVNurseVisitRec.Visible = true;
                        ibtnVace.Visible = true;
                        rptrVaceField.Visible = true;
                        rptMedicalInfo.Visible = true;
                        TMInfo.Visible = true;
                        //StudentInfoBL StdInfo = new StudentInfoBL();
                        //StudentEditInfoBL StdEditInfo = new StudentEditInfoBL();
                        //StudentBL schoolcategory = new StudentBL();

                        OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
                        OpenSISWCFServiceStudentEditClient StdEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();



                        //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);
                        // StdEditInfo.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        // StdEditInfo.StudentID = Convert.ToInt32(hdnStudentId.Value);

                        DataTable dtMedicalInfo = new DataTable();
                        dtMedicalInfo = schoolcategory.GetMedicalInfoFieldsStudentBusiness(SchoolID, CatId);
                        if (dtMedicalInfo.Rows.Count > 0)
                        {
                            rptMedicalInfo.DataSource = dtMedicalInfo;
                            rptMedicalInfo.DataBind();
                        }


                        DataTable dtImmu = StdInfo.GetImmunizationFieldValue(SchoolID, StudentID);
                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (dtImmu.Rows.Count > 0 && SessiondtImmu == null)
                        {
                            Session.Add("ImmuTable", dtImmu);
                            GVImmunization.DataSource = dtImmu;
                            GVImmunization.DataBind();
                        }
                        else
                        {
                            GVImmunization.DataSource = SessiondtImmu;
                            GVImmunization.DataBind();
                        }

                        DataTable dtAlert = StdInfo.GetMedicalAlertFieldValue(StudentID);
                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (dtAlert.Rows.Count > 0 && SessiondtAlert == null)
                        {
                            Session.Add("AlertTable", dtAlert);
                            GVMedicalAlert.DataSource = dtAlert;
                            GVMedicalAlert.DataBind();
                        }
                        else
                        {
                            GVMedicalAlert.DataSource = SessiondtAlert;
                            GVMedicalAlert.DataBind();
                        }

                        DataTable dtNurseVisit = StdInfo.GetNurseVisitFieldValue(SchoolID, StudentID);
                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (dtNurseVisit.Rows.Count > 0 && SessiondtNurseVisit == null)
                        {
                            Session.Add("NurseVisitTable", dtNurseVisit);
                            GVNurseVisitRec.DataSource = dtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }
                        else
                        {
                            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                            GVNurseVisitRec.DataBind();
                        }

                        DataTable dtMedicalInfovalue = StdEditInfo.PopulateMedicalInfoValueStudentEdit(StudentID, SchoolID);
                        DataTable MedicalInfoDataFromSession = (DataTable)Session["MedicalInfo"];

                        if (dtMedicalInfovalue.Rows.Count > 0 && MedicalInfoDataFromSession == null)
                        {
                            Session.Add("MedicalInfo", dtMedicalInfovalue);
                            PopulateMedicalInfoFieldData();
                        }
                        else
                        {
                            PopulateMedicalInfoFieldData();
                        }

                       

                        // lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";


                    }
                }
                else
                {

                    //enrollment
                    tblSchEnrInfo.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;
                    //enrollment
                    //StudentBL schoolcategory = new StudentBL();
                    tblProgram.Visible = false;
                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();


                    hdnCatId.Value = dt.Rows[0][0].ToString();
                    hdnInitialCatId.Value = hdnCatId.Value;
                    CatId = Convert.ToInt32(hdnCatId.Value);
                    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                    SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    // TreeView1.Nodes[Convert.ToInt32(hdnCatId.Value)].Selected = true;
                    // string CatName = TreeView1.SelectedNode.Text.ToString();
                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    // ibtnAdd.Visible = true;



                    this.dTable.CellPadding = 2;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;
                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");
                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);

                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);

                    }

                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        // tRows = 0;
                        int L = 0;
                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {

                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";

                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");

                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";


                                    FieldidPopulate = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    // schoolcategory.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount();
                                    //if (addressfieldcount > 0)
                                    //{
                                    DataTable dtaddressfields = schoolcategory.GetAddressFieldsByFieldIdStudentBusiness(SchoolID, FieldidPopulate, Session["MLUICulture"].ToString());
                                    //DataRow dra = dtaddressfields.NewRow();
                                    // dra["FieldName"] = dtFields.Rows[tRows]["FieldName"].ToString();
                                    // dtaddressfields.Rows.InsertAt(dra, 0);
                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;

                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);

                                    }


                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();

                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {

                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();
                                                this.dTAddCell.Align = "right";
                                                dTAddCell.Attributes.Add("class", "student_grid");

                                                this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                this.dTAddCell1.InnerText = " : ";
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");

                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                {
                                                    TextBox txt = new TextBox();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    txt.CssClass = "textbox2";
                                                    txt.ID = "txt" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    this.dTAddCell2.Controls.Add(txt);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                {
                                                    CheckBoxList chk = new CheckBoxList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    chk.ID = "chk" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(chk);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                {
                                                    RadioButtonList rdb = new RadioButtonList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    rdb.ID = "rdb" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                                                    this.dTAddCell2.Controls.Add(rdb);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                {
                                                    DropDownList ddl = new DropDownList();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    ddl.ID = "ddl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();

                                                    ddl.CssClass = "dropdown2";
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                    {
                                                        //categoryfields.populateState(ref ddl);
                                                        StuListCont.populateState(ref ddl);
                                                    }
                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "15" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "31")
                                                    {
                                                        //schoolcategory.PopulateContactRelationship(ref ddl);
                                                        StuListCont.PopulateContactRelationship(ref ddl);
                                                    }
                                                    this.dTAddCell2.Controls.Add(ddl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                {
                                                    Label lbl = new Label();
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    lbl.ID = "lbl" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(lbl);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                //**********01/05/2010*************
                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "6")
                                                {
                                                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                                    HiddenField hdnFieldAddr = new HiddenField();

                                                    control.ID = "uc" + FieldId;
                                                    hdnFieldAddr.ID = "hdnAddr" + FieldId;

                                                    hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                    this.dTAddCell2.Controls.Add(control);
                                                    this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                }
                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);
                                                dtaddressfields.Rows.RemoveAt(0);
                                                FieldId++;

                                            }



                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);

                                        }
                                        else
                                        {
                                            break;
                                        }
                                        // FieldId++;
                                    }


                                    // }

                                    this.dTCell.Controls.Add(dTAdd);
                                    dtFields.Rows.RemoveAt(0);
                                    this.dTRow.Controls.Add(this.dTCell);

                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                }
                            }

                            this.dTable.Controls.Add(dTRow);
                        }
                        else
                        {
                            break;
                        }
                    }


                    string[] SessionTable = AddTableList.Split(';');
                    if (SessionTable.Length > 1)
                    {
                        int SessionTableId = 1;
                        for (int i = 1; i < SessionTable.Length; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                string sessionTab = "Address" + SessionTableId.ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");

                                    this.dTAdd = new HtmlTable();
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + "Additional Contact" + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            chk.Items.Add("Same as Student's Home Address");
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "4" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "13" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "24" || myArrayDataFromSession.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                            {
                                                // categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                //  categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StuListCont.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //**********01/05/2010**************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        FieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                    this.dTable.Controls.Add(dTRow);

                                }

                                SessionTableId++;
                                // }
                            }

                        }
                    }
                    else
                    {
                        //enrollment
                        tblSchEnrInfo.Visible = false;
                        rptrSchlInfo.Visible = false;
                        gvEnrInfo.Visible = false;
                        tblProgram.Visible = false;
                        //enrollment

                        //StudentEditInfoBL stEditInfo = new StudentEditInfoBL();
                        //StudentBL stBL = new StudentBL();


                        OpenSISWCFServiceStudentEditClient stEditInfo = new OpenSISWCFServiceStudentEditClient();
                        IopenSISServiceStudentClient stBL = new IopenSISServiceStudentClient();

                        //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        //stBL.SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        CatId = Convert.ToInt32(hdnCatId.Value);
                        int StudentID = Convert.ToInt32(hdnStudentId.Value);

                        int HomeFieldId = 152;

                        int CheckCell = 0;
                        int RowNo = 0;
                        DataTable dtAddField = stEditInfo.GetAdditionalAddressContactSetStudentEdit(StudentID, SchoolID);
                        int mod = dtAddField.Rows.Count % 2;
                        if (mod == 0)
                        {
                            RowNo = dtAddField.Rows.Count / 2;
                        }
                        else
                        {
                            RowNo = Convert.ToInt32(dtAddField.Rows.Count / 2) + 1;

                        }
                        for (int i = 0; i < RowNo; i++)
                        {


                            this.dTRow = new HtmlTableRow();

                            for (tCells = 0; tCells < 2; tCells++)
                            {

                                DataTable myArrayDataFromSession = stBL.PopulateAdditionalFieldStudentBusiness(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());

                                if (CheckCell == dtAddField.Rows.Count)
                                {
                                    myArrayDataFromSession = null;
                                }

                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");

                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    this.dTAdd.Width = "100%";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class='heading_bevelline'>" + dtAddField.Rows[CheckCell]["ContactName"].ToString() + "</div><div class=clear_m></div>";

                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {

                                        this.dTAddRow = new HtmlTableRow();

                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerText = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");

                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "1")
                                        {
                                            TextBox txt = new TextBox();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            txt.CssClass = "textbox2";
                                            txt.ID = "txt" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(txt);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "2")
                                        {
                                            CheckBoxList chk = new CheckBoxList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            chk.ID = "chk" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            chk.Items.Add("Same as Student's Home Address");
                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(chk);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "3")
                                        {
                                            RadioButtonList rdb = new RadioButtonList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            rdb.ID = "rdb" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            rdb.RepeatDirection = RepeatDirection.Horizontal;
                                            this.dTAddCell2.Controls.Add(rdb);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "4")
                                        {
                                            DropDownList ddl = new DropDownList();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            ddl.ID = "ddl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            ddl.CssClass = "dropdown2";
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "4")
                                            {
                                                //categoryfields.populateState(ref ddl);
                                                StuListCont.populateState(ref ddl);
                                            }
                                            if (myArrayDataFromSession.Rows[m]["FieldId"].ToString() == "1")
                                            {
                                                //schoolcategory.PopulateContactRelationship(ref ddl);
                                                StuListCont.PopulateContactRelationship(ref ddl);
                                            }
                                            this.dTAddCell2.Controls.Add(ddl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "5")
                                        {
                                            Label lbl = new Label();
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            lbl.ID = "lbl" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(lbl);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        //*********01/05/2010**************
                                        if (myArrayDataFromSession.Rows[m]["FieldType"].ToString() == "6")
                                        {
                                            var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                                            HiddenField hdnFieldAddr = new HiddenField();
                                            control.ID = "uc" + FieldId;
                                            hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                            hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                            this.dTAddCell2.Controls.Add(control);
                                            this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        }
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        // myArrayDataFromSession.Rows.RemoveAt(0);
                                        FieldId++;

                                        // }

                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);

                                    }


                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }

                                    this.dTable.Controls.Add(dTRow);
                                    CheckCell++;

                                }


                                // }
                            }

                        }


                    }


                    phAllFieldHolder.Controls.Add(dTable);

                }



                btnNext.Visible = true;
                btnUpdate.Visible = false;
                if (dt.Rows.Count == 1)
                {
                    btnPrev.Visible = false;
                }
                else
                {
                    btnPrev.Visible = true;
                }
            }
        }
        catch
        {

        }

    }


    protected void PopulateFieldData()
    {
        try
        {

            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");
            dtUserData.Columns.Add("Value1");
            dtUserData.Columns.Add("FieldId1");
            dtUserData.Columns.Add("FieldCatagory1");
            //*****************27/05***********
            //dtUserData.Columns.Add("AllFieldID");
            //**********************************
            string PrevSessionTable = hdnCatId.Value.ToString();
            DataTable myArrayDataFromSession = (DataTable)Session[PrevSessionTable];

            if (myArrayDataFromSession != null)
            {

                foreach (var C in phAllFieldHolder.Controls)
                {

                    if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
                    {
                        HtmlTable dtFieldHolder = ((HtmlTable)C);

                        int TableRow = 0;
                        foreach (Control row in dtFieldHolder.Controls)
                        {

                            int TableCell = 0;

                            foreach (Control cell in row.Controls)
                            {

                                foreach (Control Con in cell.Controls)
                                {
                                    if (object.ReferenceEquals(Con.GetType(), typeof(TextBox)))
                                    {
                                        TextBox txtUserField = ((TextBox)Con);
                                        txtUserField.Text = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                        TableCell = TableCell + 3;
                                    }
                                    //**********01/05/2010**********
                                    if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                    {
                                        DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                        uc.Value = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                        TableCell = TableCell + 3;
                                    }

                                    if (object.ReferenceEquals(Con.GetType(), typeof(DropDownList)))
                                    {
                                        DropDownList ddlUserField = ((DropDownList)Con);
                                        if (myArrayDataFromSession.Rows[TableRow][TableCell].ToString() != "")
                                        {
                                            ddlUserField.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][TableCell].ToString()).Selected = true;
                                        }

                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(CheckBoxList)))
                                    {
                                        CheckBoxList ChkUserField = ((CheckBoxList)Con);
                                        for (int i = 0; i < ChkUserField.Items.Count; i++)
                                        {
                                            if (ChkUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                ChkUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(RadioButtonList)))
                                    {
                                        RadioButtonList rdoUserField = ((RadioButtonList)Con);
                                        for (int i = 0; i < rdoUserField.Items.Count; i++)
                                        {
                                            if (rdoUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                rdoUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                                    {

                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                                    {
                                        HtmlTable dtAddFieldHolder = ((HtmlTable)Con);

                                        foreach (Control Addrow in dtAddFieldHolder.Controls)
                                        {
                                            int AddCellCount = 0;

                                            foreach (Control Addcell in Addrow.Controls)
                                            {
                                                foreach (Control AddCon in Addcell.Controls)
                                                {
                                                    if (TableRow <= myArrayDataFromSession.Rows.Count - 1)
                                                    {
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(TextBox)))
                                                        {
                                                            TextBox txtUserField = ((TextBox)AddCon);
                                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString();
                                                        }

                                                        //**********01/05/2010**********
                                                        if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                                        {
                                                            DatePicker.DatePicker uc = ((DatePicker.DatePicker)AddCon);
                                                            uc.Value = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                                            //TableCell = TableCell + 3;
                                                        }
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(DropDownList)))
                                                        {
                                                            DropDownList ddlUserFieldAdd = ((DropDownList)AddCon);
                                                            if (myArrayDataFromSession.Rows[TableRow][AddCellCount].ToString() != "")
                                                            {
                                                                ddlUserFieldAdd.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString()).Selected = true;
                                                            }

                                                        }
                                                    }


                                                }

                                            }

                                            TableRow++;
                                        }

                                    }

                                }

                            }
                            TableRow++;
                        }
                    }
                }
            }
            else
            {
               
                // StudentEditInfoBL StFieldValue=new StudentEditInfoBL();
                OpenSISWCFServiceStudentEditClient StFieldValue = new OpenSISWCFServiceStudentEditClient();
                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int CatId = Convert.ToInt32(hdnCatId.Value.ToString());
                int StudentID = Convert.ToInt32(hdnStudentId.Value);
                if (hdnCatId.Value.ToString() != "3")
                {
                    DataTable dtFieldvalue = StFieldValue.PopulateFieldValueStudentEdit(SchoolID, CatId, StudentID);
                    DataRow drf = dtUserData.NewRow();
                    dtUserData.Rows.Add(drf);

                    for (int i = 0; i < dtFieldvalue.Rows.Count; i = i + 2)
                    {
                        DataRow dr = dtUserData.NewRow();
                        if (i % 2 == 0)
                        {

                            dr["Value"] = dtFieldvalue.Rows[i]["value"].ToString();
                            dr["FieldId"] = dtFieldvalue.Rows[i]["field_id"].ToString();
                            dr["FieldCatagory"] = dtFieldvalue.Rows[i]["field_category"].ToString();
                             //AllFieldID = dr["FieldId"] + "," + AllFieldID;

                            


                            string AllFieldID1 = dr["FieldId"].ToString();
                            AllFieldID = AllFieldID1 + "," + AllFieldID;

                            if (i + 1 < dtFieldvalue.Rows.Count)
                            {
                                dr["Value1"] = dtFieldvalue.Rows[i + 1]["value"].ToString();
                                dr["FieldId1"] = dtFieldvalue.Rows[i + 1]["field_id"].ToString();
                                dr["FieldCatagory1"] = dtFieldvalue.Rows[i + 1]["field_category"].ToString();
                                AllFieldID = dr["FieldId1"].ToString() + "," + AllFieldID;
                            }
                            else
                            {
                                dr["Value1"] = "";
                                dr["FieldId1"] = "";
                                dr["FieldCatagory1"] = "";
                            }
                            dtUserData.Rows.Add(dr);
                        }

                    }

                    DataRow drl = dtUserData.NewRow();
                    dtUserData.Rows.Add(drl);

                    myArrayDataFromSession = dtUserData;

                    //string str = "yourstring";
                    //str =

                    //if (CatId == 1)
                    //{

                    //    hdnStdFieldID.Value = AllFieldID.Substring(0, (AllFieldID.Length - 1));
                    //}

                    //if (CatId == 2)
                    //{
                    if (hdnStdFieldID.Value == "")
                    {
                        hdnStdFieldID.Value = "0";
                    }
                        hdnStdFieldID.Value = hdnStdFieldID.Value + "," + AllFieldID.Substring(0, (AllFieldID.Length - 1));
                    //}
                }
                else
                {

                    DataTable dtAddressField = StFieldValue.PopulateAddressFieldsStudentEdit(StudentID, CatId, SchoolID);
                    myArrayDataFromSession = dtAddressField;

                }



                foreach (var C in phAllFieldHolder.Controls)
                {

                    if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
                    {
                        HtmlTable dtFieldHolder = ((HtmlTable)C);

                        int TableRow = 0;
                        foreach (Control row in dtFieldHolder.Controls)
                        {

                            int TableCell = 0;
                            int TableCellFieldId = 1;
                            int tablecount = 0;

                            foreach (Control cell in row.Controls)
                            {

                                foreach (Control Con in cell.Controls)
                                {
                                    if (object.ReferenceEquals(Con.GetType(), typeof(TextBox)))
                                    {
                                        TextBox txtUserField = ((TextBox)Con);
                                        int FieldIdpopulate = Convert.ToInt32(myArrayDataFromSession.Rows[TableRow][TableCellFieldId].ToString());
                                        if (StFieldValue.CheckFieldValuesStudentEdit(FieldIdpopulate, CatId, StudentID) > 0)
                                        {
                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                            TableCell = TableCell + 3;
                                            TableCellFieldId = TableCellFieldId + 3;
                                        }

                                        //****************26/05
                                        else
                                        {
                                            TableCell = TableCell + 3;
                                            TableCellFieldId = TableCellFieldId + 3;
                                        }

                                    }
                                    //**********01/05/2010**********
                                    if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                    {
                                        DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                        uc.Value = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(DropDownList)))
                                    {
                                        DropDownList ddlUserField = ((DropDownList)Con);
                                        if (myArrayDataFromSession.Rows[TableRow][TableCell].ToString() != "")
                                        {
                                            ddlUserField.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][TableCell].ToString()).Selected = true;
                                        }

                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(CheckBoxList)))
                                    {
                                        CheckBoxList ChkUserField = ((CheckBoxList)Con);
                                        for (int i = 0; i < ChkUserField.Items.Count; i++)
                                        {
                                            if (ChkUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                ChkUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(RadioButtonList)))
                                    {
                                        RadioButtonList rdoUserField = ((RadioButtonList)Con);
                                        for (int i = 0; i < rdoUserField.Items.Count; i++)
                                        {
                                            if (rdoUserField.Items[i].Value == myArrayDataFromSession.Rows[TableRow][TableCell].ToString())
                                            {
                                                rdoUserField.Items[i].Selected = true;
                                            }
                                        }
                                        TableCell = TableCell + 3;
                                    }
                                    if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                                    {

                                        TableCell = TableCell + 3;
                                    }

                                    if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                                    {
                                        HtmlTable dtAddFieldHolder = ((HtmlTable)Con);
                                        tablecount = tablecount + 1;
                                        foreach (Control Addrow in dtAddFieldHolder.Controls)
                                        {
                                            int AddCellCount = 0;

                                            foreach (Control Addcell in Addrow.Controls)
                                            {
                                                foreach (Control AddCon in Addcell.Controls)
                                                {
                                                    if (TableRow <= myArrayDataFromSession.Rows.Count - 1)
                                                    {
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(TextBox)))
                                                        {
                                                            TextBox txtUserField = ((TextBox)AddCon);
                                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString();
                                                        }
                                                        //**********01/05/2010**********
                                                        if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                                        {
                                                            DatePicker.DatePicker uc = ((DatePicker.DatePicker)AddCon);
                                                            uc.Value = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                                            //TableCell = TableCell + 3;
                                                        }
                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(DropDownList)))
                                                        {
                                                            DropDownList ddlUserFieldAdd = ((DropDownList)AddCon);
                                                            if (myArrayDataFromSession.Rows[TableRow][AddCellCount].ToString() != "")
                                                            {
                                                                ddlUserFieldAdd.Items.FindByValue(myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString()).Selected = true;
                                                            }

                                                        }

                                                        if (object.ReferenceEquals(AddCon.GetType(), typeof(CheckBoxList)))
                                                        {
                                                            CheckBoxList ChkUserField = ((CheckBoxList)AddCon);
                                                            TableRow--;
                                                        }
                                                    }


                                                }

                                            }

                                            TableRow++;
                                        }
                                        if (tablecount % 2 == 0)
                                        {
                                            TableRow--;
                                        }
                                    }

                                }

                            }
                            TableRow++;
                        }
                    }
                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void StoreFieldDataIntoDatatable()
    {
        //try
        //{


        DataTable dtUserData = new DataTable();
        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        dtUserData.Columns.Add("FieldCatagory");
        dtUserData.Columns.Add("Value1");
        dtUserData.Columns.Add("FieldId1");
        dtUserData.Columns.Add("FieldCatagory1");
        int set = -3;

        foreach (var C in phAllFieldHolder.Controls)
        {
            if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
            {
                HtmlTable dtFieldHolder = ((HtmlTable)C);

                foreach (Control row in dtFieldHolder.Controls)
                {
                    int CellCount = 0;
                    DataRow dr = dtUserData.NewRow();
                    foreach (Control cell in row.Controls)
                    {

                        foreach (Control Con in cell.Controls)
                        {
                            if (object.ReferenceEquals(Con.GetType(), typeof(TextBox)))
                            {
                                TextBox txtUserField = ((TextBox)Con);
                                dr[CellCount++] = txtUserField.Text.ToString();

                            }

                            //**********01/05/2010**********
                            if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                            {
                                DatePicker.DatePicker uc = ((DatePicker.DatePicker)Con);
                                dr[CellCount++] = uc.Value.ToString();
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(DropDownList)))
                            {
                                DropDownList ddlUserField = ((DropDownList)Con);

                                if (ddlUserField.SelectedItem != null)
                                {
                                    dr[CellCount] = ddlUserField.SelectedItem.Value.ToString();
                                }
                                CellCount = CellCount + 1;

                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(CheckBoxList)))
                            {
                                string strSelected = "";
                                CheckBoxList ChkUserField = ((CheckBoxList)Con);

                                for (int i = 0; i < ChkUserField.Items.Count; i++)
                                {
                                    if (ChkUserField.Items[i].Selected)
                                    {
                                        dr[CellCount] = ChkUserField.SelectedItem.Value.ToString();
                                        strSelected = ChkUserField.Items[i].Value + "," + strSelected;
                                    }
                                }

                                //string x = strSelected.Substring(0, (strSelected.Length - 1));
                                //dr[CellCount] = strSelected.Substring(0, (strSelected.Length - 1));
                                CellCount = CellCount + 1;
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(RadioButtonList)))
                            {
                                RadioButtonList rdoUserField = ((RadioButtonList)Con);
                                for (int i = 0; i < rdoUserField.Items.Count; i++)
                                {
                                    if (rdoUserField.Items[i].Selected)
                                    {
                                        dr[CellCount] = rdoUserField.SelectedItem.Value.ToString();
                                    }
                                }
                                CellCount = CellCount + 1;
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                            {

                                CellCount++;

                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(HiddenField)))
                            {
                                HiddenField FieldId = ((HiddenField)Con);
                                dr[CellCount++] = FieldId.Value.Split("_".ToCharArray())[0];
                                dr[CellCount++] = FieldId.Value.Split("_".ToCharArray())[1];
                            }
                            if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                            {


                                HtmlTable dtAddFieldHolder = ((HtmlTable)Con);

                                foreach (Control Addrow in dtAddFieldHolder.Controls)
                                {
                                    int AddCellCount = 0;

                                    DataRow Adddr = dtUserData.NewRow();


                                    foreach (Control Addcell in Addrow.Controls)
                                    {
                                        foreach (Control AddCon in Addcell.Controls)
                                        {
                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(TextBox)))
                                            {
                                                TextBox txtUserField = ((TextBox)AddCon);
                                                Adddr[AddCellCount++] = txtUserField.Text.ToString();
                                            }
                                            //*********01/05/2010***********
                                            if (Con.GetType().Name.ToLower() == "datepicker_ascx")
                                            {
                                                DatePicker.DatePicker uc = ((DatePicker.DatePicker)AddCon);
                                                Adddr[CellCount++] = uc.Value.ToString();
                                            }
                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(DropDownList)))
                                            {
                                                DropDownList ddlUserField = ((DropDownList)AddCon);
                                                if (ddlUserField.SelectedItem != null)
                                                {
                                                    Adddr[AddCellCount] = ddlUserField.SelectedItem.Value.ToString();
                                                }
                                                AddCellCount = AddCellCount + 1;
                                            }
                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(HiddenField)))
                                            {
                                                HiddenField hdnFieldAddr = ((HiddenField)AddCon);
                                                HiddenField hdnDefFieldId = ((HiddenField)AddCon);
                                                Adddr[AddCellCount++] = hdnFieldAddr.Value.Split("_".ToCharArray())[0];
                                                Adddr[AddCellCount++] = hdnFieldAddr.Value.Split("_".ToCharArray())[1];
                                                Adddr[3] = set;
                                                if (set <= 0)
                                                {
                                                    if (hdnFieldAddr.Value.Split("_".ToCharArray()).Length == 3)
                                                    {

                                                        if (hdnFieldAddr.Value.Split("_".ToCharArray())[2] != "")
                                                        {
                                                            Adddr[4] = hdnFieldAddr.Value.Split("_".ToCharArray())[2];
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                    }
                                    dtUserData.Rows.Add(Adddr);
                                }

                                set++;
                            }

                        }

                    }
                    dtUserData.Rows.Add(dr);
                }
            }
        }

        string SessionTableName = hdnCatId.Value.ToString();
        Session.Add(SessionTableName, dtUserData);


        //}
        //catch (Exception ex)
        //    {
        //        string EX = ex.ToString();
        //    }



    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            //StudentEditInfoBL EditFieldValue = new StudentEditInfoBL();
            //StudentBL StudentAdd = new StudentBL();

            OpenSISWCFServiceStudentEditClient EditFieldValue = new OpenSISWCFServiceStudentEditClient();
            IopenSISServiceStudentClient StudentAdd = new IopenSISServiceStudentClient();

            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            // StudentAdd.SchoolID = Convert.ToInt32(Session["SchoolID"]);
            DataTable dt = EditFieldValue.GetSchoolSpecificCategoryStudentEdit(SchoolID);
            int StdId = Convert.ToInt32(hdnStudentId.Value);
            int FieldId = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][0].ToString() != "3")
                {

                    if (dt.Rows[i][0].ToString() != "5")
                    {
                        if (dt.Rows[i][0].ToString() != "4")
                        {
                            if (dt.Rows[i][0].ToString() != "8")
                            {
                                string SessionTable = dt.Rows[i][0].ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[SessionTable];
                               
                                if (myArrayDataFromSession != null)
                                {
                                    //******************27/05/10(delete)**********
                                        EditFieldValue.DeleteStudentDetailsFieldIDStudentEdit(StdId, Convert.ToInt32(dt.Rows[i][0]), hdnStdFieldID.Value);
                                        //**************************************
                                    for (int j = 0; j < myArrayDataFromSession.Rows.Count; j++)
                                    {
                                        

                                        if (myArrayDataFromSession.Rows[j][1].ToString() != "" && myArrayDataFromSession.Rows[j][4].ToString() != "")
                                        {
                                            int StudentID = StdId;
                                            string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                            FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                            //StudentAdd.FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                            string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                            int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                            //EditFieldValue.UpdateStudentDetailsStudentEdit(Value, CatId, StudentID, FieldId, FieldCategory);
                                            StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);
                                            FieldCategory = myArrayDataFromSession.Rows[j][5].ToString();
                                            FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][4]);
                                            Value = myArrayDataFromSession.Rows[j][3].ToString();
                                            //EditFieldValue.UpdateStudentDetailsStudentEdit(Value, CatId, StudentID, FieldId, FieldCategory);
                                            StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);

                                        }
                                        else
                                        {
                                            if (myArrayDataFromSession.Rows[j][1].ToString() != "")
                                            {
                                                int StudentID = StdId;
                                                string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                                FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                                string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                                int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                                //EditFieldValue.UpdateStudentDetailsStudentEdit(Value, CatId, StudentID, FieldId, FieldCategory);
                                                StudentAdd.InsertIntoStudentDetailsStudentBusiness(StudentID, FieldCategory, FieldId, Value, CatId);

                                            }
                                        }

                                    }
                                }
                            }
                            else
                            //********** if (dt.Rows[i][0].ToString() != "8")****************************
                            {
                                int StudentID = StdId;
                                DataTable SessiondtspecialEdu = (DataTable)Session["SpecialEduForInsert"];

                                if (SessiondtspecialEdu != null)
                                {

                                    EditFieldValue.DeleteProgramsSpecialEducationDetailsStudentEdit(StudentID, Convert.ToInt32(Session["SchoolID"]));
                                    for (int Specrowid = 0; Specrowid <= SessiondtspecialEdu.Rows.Count - 1; Specrowid++)
                                    {
                                        //string Value = SessiondtspecialEdu.Rows[Specrowid][0].ToString();
                                        string Value = SessiondtspecialEdu.Rows[Specrowid]["Value"].ToString();

                                        //  FieldId = Convert.ToInt32(SessiondtspecialEdu.Rows[Specrowid][1].ToString());
                                        FieldId = Convert.ToInt32(SessiondtspecialEdu.Rows[Specrowid]["FieldId"].ToString());
                                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                        StudentID = StdId;
                                        int CatId = Convert.ToInt32(SessiondtspecialEdu.Rows[Specrowid]["Cat_Id"].ToString());
                                        StudentAdd.InsertSpecialValueStudentBusiness(FieldId, CatId, StudentID, Value, SchoolID);

                                    }

                                }

                                DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];

                                if (SessiondtGift != null)
                                {
                                    EditFieldValue.DeleteProgramsGiftedDetailsStudentEdit(StudentID, Convert.ToInt32(Session["SchoolID"]));
                                    for (int Giftrowid = 0; Giftrowid <= SessiondtGift.Rows.Count - 1; Giftrowid++)
                                    {
                                        //string Value = SessiondtGift.Rows[Giftrowid][0].ToString();
                                        //FieldId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid][1].ToString());
                                        string Value = SessiondtGift.Rows[Giftrowid]["Value"].ToString();
                                        FieldId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid]["FieldId"].ToString());
                                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                        StudentID = StdId;
                                        //int CatId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid][4].ToString()); ;
                                        int CatId = Convert.ToInt32(SessiondtGift.Rows[Giftrowid]["Cat_Id"].ToString());
                                        StudentAdd.InsertgiftedValueStudentBusiness(FieldId, CatId, Value, SchoolID, StudentID);

                                    }

                                }



                            }
                            //********** if (dt.Rows[i][0].ToString() != "8")end else****************************
                        }
                        else
                        {

                            //for enrollment

                            DataTable SchoolinfoSession = (DataTable)Session["SchoolInfo"];
                            if (SchoolinfoSession != null)
                            {
                                for (int Srowid = 0; Srowid <= SchoolinfoSession.Rows.Count - 1; Srowid++)
                                {
                                    int StudentID = StdId;
                                    string FieldCategory = SchoolinfoSession.Rows[Srowid]["FieldCatagory"].ToString();
                                    FieldId = Convert.ToInt32(SchoolinfoSession.Rows[Srowid]["FieldId"]);
                                    string Value = SchoolinfoSession.Rows[Srowid]["Value"].ToString();
                                    int CatId = Convert.ToInt32(dt.Rows[i][0]);

                                    //*************check record

                                    EditFieldValue.UpdateStudentDetailsStudentEdit(Value, CatId, StudentID, FieldId, FieldCategory);

                                }
                            }




                            DataTable EnrollmentInfoDataFromSession = (DataTable)Session["Enroltable"];




                            if (EnrollmentInfoDataFromSession != null)
                            {
                                if (!EnrollmentInfoDataFromSession.Columns.Contains("temp"))
                                {
                                    EnrollmentInfoDataFromSession.Columns.Add("temp");

                                }

                                for (int Enrow = 0; Enrow <= EnrollmentInfoDataFromSession.Rows.Count - 1; Enrow++)
                                {
                                    IopenSISServiceStudentClient StBL = new IopenSISServiceStudentClient();



                                    if (EnrollmentInfoDataFromSession.Rows[Enrow]["temp"].ToString() == "Add")
                                    {
                                        int StudentID = StdId;
                                        SchoolID = Convert.ToInt32(Session["SchoolID"]);
                                        string EnrAttStartdate = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_Start_Date"].ToString();
                                        string EnrExitDate = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_End_Date"].ToString();
                                        string EnrExitCode = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_Code_Id"].ToString();
                                        string EnrExitreason = EnrollmentInfoDataFromSession.Rows[Enrow]["Exit_Reason"].ToString();
                                        string EnrStartCondition = EnrollmentInfoDataFromSession.Rows[Enrow]["Start_Condition"].ToString();
                                        // ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
                                        //string s = ddlFullYear.SelectedItem.Value;
                                        int EnrSchyrId = Convert.ToInt32(Session["FullYear"]);
                                        if (EnrSchyrId == 0)
                                        {
                                            EnrSchyrId = 2;
                                        }
                                        StBL.InsertEnrollmentStudentBusiness(EnrAttStartdate, EnrExitDate, StudentID, SchoolID, EnrSchyrId, EnrExitCode, EnrExitreason, EnrStartCondition);


                                    }
                                    else if (EnrollmentInfoDataFromSession.Rows[Enrow]["temp"].ToString() == "")
                                    {
                                        int EnrollId = Convert.ToInt32(EnrollmentInfoDataFromSession.Rows[Enrow]["Std_Enr_Id"].ToString());
                                        string EnrAttStartdate = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_Start_Date"].ToString();
                                        string EnrExitDate = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_End_Date"].ToString();
                                        string EnrExitCode = EnrollmentInfoDataFromSession.Rows[Enrow]["Enr_Code_Id"].ToString();
                                        string EnrExitreason = EnrollmentInfoDataFromSession.Rows[Enrow]["Exit_Reason"].ToString();
                                        string EnrStartCondition = EnrollmentInfoDataFromSession.Rows[Enrow]["Start_Condition"].ToString();
                                        //  ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
                                        //string s = ddlFullYear.SelectedItem.Value;
                                        int EnrSchyrId = Convert.ToInt32(Session["FullYear"]);
                                        if (EnrSchyrId == 0)
                                        {
                                            EnrSchyrId = 2;
                                        }
                                        StBL.UpdateEnrollmentStudentBusiness(EnrAttStartdate, EnrExitDate, EnrExitCode, EnrExitreason, EnrStartCondition, EnrollId);


                                    }


                                }
                            }








                        }
                    }
                    else
                    {

                        int StudentID = StdId;
                        //  StudentAdd.StudentID = StdId;
                        if (Session["ImmuTable"] != null || Session["AlertTable"] != null || Session["NurseVisitTable"] != null || Session["VaccinationForInsert"] != null)
                        {

                            EditFieldValue.DeleteAllMedicalInformationStudentEdit(StudentID, SchoolID);
                        }
                        string PrevSessionTable = "MedicalInfo";
                        DataTable MedicalInfoDataFromSession = (DataTable)Session[PrevSessionTable];
                        if (MedicalInfoDataFromSession != null)
                        {

                            for (int Mrowid = 0; Mrowid <= MedicalInfoDataFromSession.Rows.Count - 1; Mrowid++)
                            {
                                StudentID = StdId;
                                string Value = MedicalInfoDataFromSession.Rows[Mrowid][0].ToString();
                                int MedInfoId = Convert.ToInt32(MedicalInfoDataFromSession.Rows[Mrowid][1].ToString());
                                EditFieldValue.UpdateMedicalInfoStudentEdit(Value, SchoolID, StudentID, MedInfoId);

                            }
                        }

                        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
                        if (SessiondtImmu != null)
                        {
                            for (int MInfoid = 0; MInfoid <= SessiondtImmu.Rows.Count - 1; MInfoid++)
                            {

                                int MedInfoType = Convert.ToInt32(SessiondtImmu.Rows[MInfoid]["Type"].ToString());
                                string MedInfoDate = SessiondtImmu.Rows[MInfoid]["Date"].ToString();
                                string Comments = SessiondtImmu.Rows[MInfoid]["Comment"].ToString();
                                StudentAdd.InsertIntoStudentImmunizationDetailsStudentBusiness(MedInfoType, MedInfoDate, Comments, SchoolID, StudentID, FieldId);



                            }
                        }

                        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
                        if (SessiondtAlert != null)
                        {
                            for (int Alertid = 0; Alertid <= SessiondtAlert.Rows.Count - 1; Alertid++)
                            {


                                string Value = SessiondtAlert.Rows[Alertid]["Alert"].ToString();
                                int LifeThreatInd = 0;
                                int MedAlertActId = 0;
                                StudentAdd.InsertIntoStudentMedicalAlertStudentBusiness(StudentID, MedAlertActId, Value, LifeThreatInd);



                            }
                        }

                        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
                        if (SessiondtNurseVisit != null)
                        {
                            for (int Nurserowid = 0; Nurserowid <= SessiondtNurseVisit.Rows.Count - 1; Nurserowid++)
                            {

                                string NurseVisitDate = SessiondtNurseVisit.Rows[Nurserowid]["Date"].ToString();
                                string NurseVisitTimeIn = SessiondtNurseVisit.Rows[Nurserowid]["TimeIn"].ToString();
                                string NurseVisitTimeOut = SessiondtNurseVisit.Rows[Nurserowid]["TimeOut"].ToString();
                                string NurseVisitReason = SessiondtNurseVisit.Rows[Nurserowid]["Reason"].ToString();
                                string NurseVisitResult = SessiondtNurseVisit.Rows[Nurserowid]["Result"].ToString();
                                string Comments = SessiondtNurseVisit.Rows[Nurserowid]["Comments"].ToString();
                                StudentAdd.InsertIntoStudentNurseVisitRecordDetailsStudentBusiness(NurseVisitDate, NurseVisitTimeIn, NurseVisitTimeOut, NurseVisitReason, NurseVisitResult, Comments, StudentID, SchoolID);


                            }
                        }



                        DataTable VaccinationDataFromSession = (DataTable)Session["VaccinationForInsert"];

                        if (VaccinationDataFromSession != null)
                        {

                            for (int Vaccrowid = 0; Vaccrowid <= VaccinationDataFromSession.Rows.Count - 1; Vaccrowid++)
                            {
                                string Value = VaccinationDataFromSession.Rows[Vaccrowid]["Value"].ToString();
                                FieldId = Convert.ToInt32(VaccinationDataFromSession.Rows[Vaccrowid]["FieldId"].ToString());
                                StudentAdd.InsertIntoStudentVaccinationRecordDetailsStudentBusiness(StudentID, SchoolID, Value, FieldId);

                            }

                        }



                    }
                }
                else
                {

                    string SessionTable = dt.Rows[i][0].ToString();
                    DataTable myArrayDataFromSession = (DataTable)Session[SessionTable];
                    if (myArrayDataFromSession != null)
                    {
                        int k = 1;
                        for (int j = 0; j < myArrayDataFromSession.Rows.Count; j++)
                        {

                            if (myArrayDataFromSession.Rows[j][1].ToString() != "")
                            {
                                if (myArrayDataFromSession.Rows[j][2].ToString() == "D")
                                {
                                    int StudentID = StdId;
                                    string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                    int AddId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                    FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][4]);
                                    string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                    int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                    EditFieldValue.UpdateAddressDetailsStudentEdit(Value, StudentID, CatId, SchoolID, AddId);
                                }
                                else
                                {
                                    int StudentID = StdId;
                                    string FieldCategory = myArrayDataFromSession.Rows[j][2].ToString();
                                    FieldId = Convert.ToInt32(myArrayDataFromSession.Rows[j][1]);
                                    string Value = myArrayDataFromSession.Rows[j][0].ToString();
                                    int Set = Convert.ToInt32(myArrayDataFromSession.Rows[j][3]);
                                    int CatId = Convert.ToInt32(dt.Rows[i][0]);
                                    int ContSetId = k++;
                                    EditFieldValue.UpdateAdditionalContactDetailsStudentEdit(Value, StudentID, Set, SchoolID, ContSetId);
                                    //int CheckConSet = EditFieldValue.CountSetFields();
                                    // if (CheckConSet == k)
                                    // {
                                    //   k = 1;
                                    // }
                                }
                            }
                        }
                    }

                }
            }


            //*********************************photo save(saikat-14/10/2009)***********************************


            if (EditFieldValue.GetPhotoCountStudentEdit(StdId, SchoolID) > 0)
            {
                int StudentID = Convert.ToInt32(hdnStudentId.Value);
                string PhotoUrl = Session["StudentImage"].ToString().Replace("~", "..");
                EditFieldValue.UpdateStudentPhotoStudentEdit(PhotoUrl, StudentID, SchoolID);
            }
            else
            {
                int StudentID = Convert.ToInt32(hdnStudentId.Value);
                string PhotoUrl = Session["StudentImage"].ToString().Replace("~", "..");
                StudentAdd.SaveStudentPhotoStudentBusiness(StudentID, SchoolID, PhotoUrl);
            }
            string uploadedimage = "~/Garbage Image/" + Session["WorkingImage"].ToString();
            File.Delete(Server.MapPath(uploadedimage));
            Session["WorkingImage"] = null;
            Session["StudentImage"] = null;
            //*********************************photo save(saikat-14/10/2009)***********************************
        }
        catch (Exception Ex)
        {
            string ex = Ex.ToString();
        }
        finally
        {
            OpenSISWCFServiceStudentEditClient EditFieldValue = new OpenSISWCFServiceStudentEditClient();
            ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            DataTable dt = EditFieldValue.GetSchoolSpecificCategoryStudentEdit(SchoolID);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Session[dt.Rows[i]["Cat_Id"].ToString()] = null;
            }

            string[] SessionTable = AddTableList.Split(';');
            int SessionTableId = 1;
            for (int i = 1; i < SessionTable.Length; i++)
            {
                string sessionTab = "Address" + SessionTableId.ToString();
                Session[sessionTab] = null;
            }
            Session["SchoolInfo"] = null;
            Session["Enroltable"] = null;
            Session["MedicalInfo"] = null;
            Session["ImmuTable"] = null;
            Session["AlertTable"] = null;
            Session["NurseVisitTable"] = null;
            Session["VaccinationForInsert"] = null;
            Session["VaccinationForGrid"] = null;
            Session["SpecialGiftForInsert"] = null;
            Session["SpecialEduForInsert"] = null;
        }
        Response.Redirect("StudentInfo.aspx");
    }

    protected void ClearSession()
    {


        OpenSISWCFServiceStudentEditClient EditFieldValue = new OpenSISWCFServiceStudentEditClient();
        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        DataTable dt = EditFieldValue.GetSchoolSpecificCategoryStudentEdit(SchoolID);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            Session[dt.Rows[i]["Cat_Id"].ToString()] = null;
        }

        string[] SessionTable = AddTableList.Split(';');
        int SessionTableId = 1;
        for (int i = 1; i < SessionTable.Length; i++)
        {
            string sessionTab = "Address" + SessionTableId.ToString();
            Session[sessionTab] = null;
        }
        Session["SchoolInfo"] = null;
        Session["Enroltable"] = null;
        Session["MedicalInfo"] = null;
        Session["ImmuTable"] = null;
        Session["AlertTable"] = null;
        Session["NurseVisitTable"] = null;
        Session["VaccinationForInsert"] = null;
        Session["VaccinationForGrid"] = null;
        Session["SpecialGiftForInsert"] = null;
        Session["SpecialEduForInsert"] = null;
    }

    protected void btnImmuAdd_Click(object sender, ImageClickEventArgs e)
    {

        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            //DataTable dtImmuDetails = new DataTable();
            //dtImmuDetails.Columns.Add("Type");
            //dtImmuDetails.Columns.Add("Date");
            //dtImmuDetails.Columns.Add("Comment");
            //dtImmuDetails.Columns.Add("Typevalue");
            //DataRow dr = dtImmuDetails.NewRow();
            //dtImmuDetails.Rows.Add(dr);
            //GVImmunization.DataSource = dtImmuDetails;
            //GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
       
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
       

       
       

        ModalPopupExtender2.Enabled = true;
        ModalPopupExtender2.Show();
        //**********03/05/2010**********
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }

    }

    protected void ibtnAlertAdd_Click(object sender, ImageClickEventArgs e)
    {

       
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            //DataTable dtAlertDetails = new DataTable();
            //dtAlertDetails.Columns.Add("Alert");
            //DataRow dr = dtAlertDetails.NewRow();
            //dtAlertDetails.Rows.Add(dr);
            //GVMedicalAlert.DataSource = dtAlertDetails;
            //GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }


      

        ModalPopupExtender3.Enabled = true;
        ModalPopupExtender3.Show();
        btnPrev.Visible = true;


    }

    protected void ibtnNursevisitAdd_Click(object sender, ImageClickEventArgs e)
    {

       
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
       
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
       
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            //DataTable dtNurseVisitDetails = new DataTable();
            //dtNurseVisitDetails.Columns.Add("Date");
            //dtNurseVisitDetails.Columns.Add("TimeIn");
            //dtNurseVisitDetails.Columns.Add("TimeOut");
            //dtNurseVisitDetails.Columns.Add("Reason");
            //dtNurseVisitDetails.Columns.Add("Result");
            //dtNurseVisitDetails.Columns.Add("Comments");
            //DataRow dr = dtNurseVisitDetails.NewRow();
            //dtNurseVisitDetails.Rows.Add(dr);
            //GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            //GVNurseVisitRec.DataBind();

        }

     
        ModalPopupExtender4.Enabled = true;
        ModalPopupExtender4.Show();
        btnPrev.Visible = true;


    }

    protected void ibtnVace_Click(object sender, ImageClickEventArgs e)
    {

        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
       
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        

        //DataTable dtVaccinationDetails = new DataTable();
        //dtVaccinationDetails.Columns.Add("Vaccination_Code");
        //dtVaccinationDetails.Columns.Add("Vaccination_Name");
        //dtVaccinationDetails.Columns.Add("Vaccination_Date");
        //dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
        //dtVaccinationDetails.Columns.Add("Waiver");

        //DataRow drvacc = dtVaccinationDetails.NewRow();
        //dtVaccinationDetails.Rows.Add(drvacc);
        //GVVccination.DataSource = dtVaccinationDetails;
        //GVVccination.DataBind();

        // PopulateMedicalInfoFieldData();
        //PopulateVccinationGridview();

        DataTable dtVcea = new DataTable();
        dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(Convert.ToInt32(Session["SchoolID"]), Convert.ToInt32(hdnCatId.Value));
        rptrVaceField.DataSource = dtVcea;
        rptrVaceField.DataBind();

        ModalPopupExtender5.Enabled = true;
        ModalPopupExtender5.Show();
        btnPrev.Visible = true;

    }

    protected void btnImmuSave_Click(object sender, EventArgs e)
    {
        try
        {

            //StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
            if (SessiondtImmu == null)
            {
                DataTable dtImmuDetails = new DataTable();
                dtImmuDetails.Columns.Add("Type");
                dtImmuDetails.Columns.Add("Date");
                dtImmuDetails.Columns.Add("Comment");
                // dtImmuDetails.Columns.Add("Typevalue");


                DataRow dr = dtImmuDetails.NewRow();

                dr["Type"] = ddlImmunaization.SelectedItem.Value;
                dr["Date"] = txtdate.Text.ToString();
                dr["Comment"] = txtcomments.Text.ToString();
                // dr["Typevalue"] = ddlImmunaization.SelectedItem.Value;

                dtImmuDetails.Rows.Add(dr);
                GVImmunization.DataSource = dtImmuDetails;
                GVImmunization.DataBind();
                Session.Add("ImmuTable", dtImmuDetails);

            }
            else
            {
                DataRow dr = SessiondtImmu.NewRow();
                dr["Type"] = ddlImmunaization.SelectedItem.Value;
                dr["Date"] = txtdate.Text.ToString();
                dr["Comment"] = txtcomments.Text.ToString();
                // dr["Typevalue"] = ddlImmunaization.SelectedItem.Value;

                SessiondtImmu.Rows.Add(dr);
                GVImmunization.DataSource = SessiondtImmu;
                GVImmunization.DataBind();
                Session.Add("ImmuTable", SessiondtImmu);

            }

            //  PopulateMedicalInfoFieldData();
            //   PopulateVccinationGridview();

           
            ModalPopupExtender2.Enabled = false;
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }

    protected void btnAlertSave_Click(object sender, EventArgs e)
    {
        try
        {
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
            if (SessiondtAlert == null)
            {
                DataTable dtAlertDetails = new DataTable();
                dtAlertDetails.Columns.Add("Alert");
                DataRow dr = dtAlertDetails.NewRow();


                dr["Alert"] = txtAlerts.Text.ToString();

                dtAlertDetails.Rows.Add(dr);


                GVMedicalAlert.DataSource = dtAlertDetails;
                GVMedicalAlert.DataBind();
                Session.Add("AlertTable", dtAlertDetails);
            }
            else
            {
                DataRow dr = SessiondtAlert.NewRow();
                dr["Alert"] = txtAlerts.Text.ToString();

                SessiondtAlert.Rows.Add(dr);
                GVMedicalAlert.DataSource = SessiondtAlert;
                GVMedicalAlert.DataBind();
                Session.Add("AlertTable", SessiondtAlert);

            }


       
            // PopulateMedicalInfoFieldData();
            // PopulateVccinationGridview();
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }

    protected void btnNurseVisitSave_Click(object sender, EventArgs e)
    {
        try
        {
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
            if (SessiondtNurseVisit == null)
            {
                DataTable dtNurseVisitDetails = new DataTable();
                dtNurseVisitDetails.Columns.Add("Date");
                dtNurseVisitDetails.Columns.Add("TimeIn");
                dtNurseVisitDetails.Columns.Add("TimeOut");
                dtNurseVisitDetails.Columns.Add("Reason");
                dtNurseVisitDetails.Columns.Add("Result");
                dtNurseVisitDetails.Columns.Add("Comments");



                DataRow dr = dtNurseVisitDetails.NewRow();

                dr["Date"] = txtNurseVisitDate.Text.ToString();
                dr["TimeIn"] = txtTimeIn.Text.ToString();
                dr["TimeOut"] = txtTimeOut.Text.ToString();
                dr["Reason"] = txtReason.Text.ToString();
                dr["Result"] = txtResult.Text.ToString();
                dr["Comments"] = txtNurseComments.Text.ToString();

                dtNurseVisitDetails.Rows.Add(dr);


                GVNurseVisitRec.DataSource = dtNurseVisitDetails;
                GVNurseVisitRec.DataBind();
                Session.Add("NurseVisitTable", dtNurseVisitDetails);
            }
            else
            {
                DataRow dr = SessiondtNurseVisit.NewRow();

                dr["Date"] = txtNurseVisitDate.Text.ToString();
                dr["TimeIn"] = txtTimeIn.Text.ToString();
                dr["TimeOut"] = txtTimeOut.Text.ToString();
                dr["Reason"] = txtReason.Text.ToString();
                dr["Result"] = txtResult.Text.ToString();
                dr["Comments"] = txtNurseComments.Text.ToString();

                SessiondtNurseVisit.Rows.Add(dr);
                GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                GVNurseVisitRec.DataBind();
                Session.Add("NurseVisitTable", SessiondtNurseVisit);

            }

            

            //  PopulateMedicalInfoFieldData();
            //  PopulateVccinationGridview();

            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }


    }

    protected void btnvcciSave_Click(object sender, EventArgs e)
    {
        ////DataTable SessiondtVaccination = (DataTable)Session["VaccinationForGrid"];
        ////if (SessiondtVaccination == null)
        ////{
        ////    DataTable dtVaccinationDetails = new DataTable();
        ////    dtVaccinationDetails.Columns.Add("Vaccination_Code");
        ////    dtVaccinationDetails.Columns.Add("Vaccination_Name");
        ////    dtVaccinationDetails.Columns.Add("Vaccination_Date");
        ////    dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
        ////    dtVaccinationDetails.Columns.Add("Waiver");

        ////    foreach (var C in panel_Vaccination.Controls)
        ////    {

        ////        if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
        ////        {

        ////            Repeater rptrVaceField = ((Repeater)C);
        ////            DataRow drvacc = dtVaccinationDetails.NewRow();
        ////            for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
        ////            {
        ////                TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

        ////                if (txtfieldvalue != null)
        ////                {
        ////                    drvacc[i] = txtfieldvalue.Text.ToString();
        ////                    //txtfieldvalue.Text = "";
        ////                }
        ////                //***********01/05/2010*********
        ////                DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
        ////                if (uc != null)
        ////                {
        ////                    drvacc[i] = uc.Value.ToString();
        ////                    //uc.Value = "";
        ////                }
        ////            }
        ////            dtVaccinationDetails.Rows.Add(drvacc);
        ////        }
        ////    }

        ////    GVVccination.DataSource = dtVaccinationDetails;
        ////    GVVccination.DataBind();
        ////    Session.Add("VaccinationForGrid", dtVaccinationDetails);
            

        ////}
        ////else
        ////{
        ////    DataRow drvacc = SessiondtVaccination.NewRow();
        ////    foreach (var C in panel_Vaccination.Controls)
        ////    {

        ////        if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
        ////        {

        ////            Repeater rptrVaceField = ((Repeater)C);

        ////            for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
        ////            {
        ////                TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

        ////                if (txtfieldvalue != null)
        ////                {
        ////                    drvacc[i] = txtfieldvalue.Text.ToString();
        ////                    //txtfieldvalue.Text = "";
        ////                }
        ////                //**********01/05/2010***********
        ////                DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
        ////                if (uc != null)
        ////                {
        ////                    drvacc[i] = uc.Value.ToString();
        ////                   // uc.Value = "";
        ////                }
        ////            }

        ////        }
        ////    }
        ////    SessiondtVaccination.Rows.Add(drvacc);
        ////    GVVccination.DataSource = SessiondtVaccination;
        ////    GVVccination.DataBind();
        ////    Session.Add("VaccinationForGrid", SessiondtVaccination);
        ////}

        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtVaccination = (DataTable)Session["VaccinationForInsert"];
        if (SessiondtVaccination == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
           
            dtUserData.Columns.Add("FieldType");
            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrVaceField.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVaceField.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldType");
                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }
                        //dr["Cat_Id"] = hdnCatId.Value.ToString();

                        dtUserData.Rows.Add(dr);
                    }
                }
            }







            string SessionTableName = "VaccinationForInsert";
            Session.Add(SessionTableName, dtUserData);

            rptrVccination.DataSource = dtUserData;
            rptrVccination.DataBind();
        }
        else
        {

            foreach (var C in panel_Vaccination.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {
                    Repeater rptrVaceField = ((Repeater)C);
                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtVaccination.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrVaceField.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVaceField.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldType");

                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }

                        // dr[4] = hdnCatId.Value.ToString();
                        // dr["Cat_Id"] = hdnCatId.Value.ToString();

                        SessiondtVaccination.Rows.Add(dr);
                    }
                }
            }
           

            Session.Add("VaccinationForInsert", SessiondtVaccination);
            rptrVccination.DataSource = SessiondtVaccination;
            rptrVccination.DataBind();
        }

       
    }

    //protected void btnvcciCancel_Click(object sender, EventArgs e)
    //{
    //    ModalPopupExtender5.Enabled = false;
    //    ModalPopupExtender5.Show();
    //    btnPrev.Visible = true;

    //}

    protected void rptMedicalInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                    //{
                    //    vmlBL.populateEthnicity(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                    //{
                    //    vmlBL.populateLanguage(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                    //{
                    //    vmlBL.populateCountry(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    //{
                    //    // vmlBL.populateCountry(ref ddl);
                    //    vmlBL.PopulateEnrollCdn(ref ddl);
                    //}
                    // maindiv.Controls.Add(ddl);
                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }


            }
            //else if (hdnDefCus.Value.ToString().Trim() == "C")
            //{
            //    if (hdnFieldType.Value.ToString() == "1")
            //    {
            //        TextBox txt = new TextBox();
            //        txt.ID = "txt";
            //        txt.Width = 100;

            //        maindiv.Controls.Add(txt);

            //    }
            //    if (hdnFieldType.Value.ToString() == "2")
            //    {
            //        CheckBoxList chk = new CheckBoxList();
            //        chk.ID = "chk";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrchk(ref chk);
            //        chk.RepeatDirection = RepeatDirection.Horizontal;
            //        maindiv.Controls.Add(chk);
            //    }
            //    if (hdnFieldType.Value.ToString() == "3")
            //    {
            //        RadioButtonList rdb = new RadioButtonList();
            //        rdb.ID = "rdb";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrbtn(ref rdb);
            //        rdb.RepeatDirection = RepeatDirection.Horizontal;

            //        maindiv.Controls.Add(rdb);
            //    }
            //    if (hdnFieldType.Value.ToString() == "4")
            //    {
            //        DropDownList ddl = new DropDownList();
            //        ddl.ID = "ddl";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicddl(ref ddl);
            //        ddl.AutoPostBack = false;
            //        maindiv.Controls.Add(ddl);

            //    }
            //    if (hdnFieldType.Value.ToString() == "5")
            //    {
            //        Label lbl = new Label();
            //        lbl.ID = "lbl";
            //        StudentBL stbl2 = new StudentBL();

            //        maindiv.Controls.Add(lbl);
            //    }
            //}

            //if (hdnDefCus.Value.ToString().Trim() == "D")
            //{
            //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
            //    {
            //        e.Item.Visible = false;
            //    }
            //}
            // fieldid++;

        }
        catch { }


    }

    protected DataTable PopulateVacciGrid()
    {
        // StudentInfoBL StdInfo = new StudentInfoBL();
        OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
        // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        int StudentID = Convert.ToInt32(hdnStudentId.Value);
        DataTable dt = StdInfo.GetVaccinationFieldValue(SchoolID, StudentID);
        DataTable dtVaccinationDetails = new DataTable();
        dtVaccinationDetails.Columns.Add("Vaccination_Code");
        dtVaccinationDetails.Columns.Add("Vaccination_Name");
        dtVaccinationDetails.Columns.Add("Vaccination_Date");
        dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
        dtVaccinationDetails.Columns.Add("Waiver");


        int j = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (i % 5 == 0)
            {
                drvacc = dtVaccinationDetails.NewRow();
                j = 0;
                dtVaccinationDetails.Rows.Add(drvacc);
            }
            drvacc[j] = dt.Rows[i][3];

            j++;
        }

        return dtVaccinationDetails;

    }

    protected void GVImmunization_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       // DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

           
            HiddenField hdnImmunizationType = (HiddenField)e.Row.FindControl("hdnImmunizationType");
            DropDownList ddlImmunaizationEdit = (DropDownList)e.Row.FindControl("ddlImmunaizationTypeEdit");
            Label lblImmunizationType = (Label)e.Row.FindControl("lblImmunizationType");
            if (lblImmunizationType != null)
            {
                if (lblImmunizationType.Text == "0")
                {
                    lblImmunizationType.Text = "Select";
                }
                if (lblImmunizationType.Text == "1")
                {
                    lblImmunizationType.Text = "Imunization";
                }
                if (lblImmunizationType.Text == "2")
                {
                    lblImmunizationType.Text = "Physical";
                }
            }
            if (ddlImmunaizationEdit != null && hdnImmunizationType.Value != "")
            {
                ddlImmunaizationEdit.Items.FindByValue(hdnImmunizationType.Value).Selected = true;
            }
        }

    }

   

    protected void PopulateMedicalInfoFieldData()
    {
        try
        {

            string PrevSessionTable = "MedicalInfo";
            DataTable MedicalInfoDataFromSession = (DataTable)Session[PrevSessionTable];

            if (MedicalInfoDataFromSession != null)
            {
                int v = 0;


                for (int i = 0; i <= rptMedicalInfo.Items.Count - 1; i++)
                {

                    TextBox txtfieldvalue = (TextBox)rptMedicalInfo.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = MedicalInfoDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptMedicalInfo.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {


                    }
                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void StoreMedicalInfoFieldDataIntoDatatable()
    {


        DataTable dtUserData = new DataTable();
        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        // dtUserData.Columns.Add("FieldCatagory");

        for (int i = 0; i <= rptMedicalInfo.Items.Count - 1; i++)
        {
            DataRow dr = dtUserData.NewRow();
            TextBox txtfieldvalue = (TextBox)rptMedicalInfo.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptMedicalInfo.Items[i].FindControl("hdnFieldId");
            if (txtfieldvalue != null)
            {
                dr[0] = txtfieldvalue.Text.ToString();
                dr[1] = hdnFieldId.Value.ToString();
            }
            DropDownList ddlfieldvalue = (DropDownList)rptMedicalInfo.Items[i].FindControl("ddl");
            if (ddlfieldvalue != null)
            {
                dr[0] = ddlfieldvalue.SelectedItem.Text.ToString();

            }

            dtUserData.Rows.Add(dr);
        }

        string SessionTableName = "MedicalInfo";
        Session.Add(SessionTableName, dtUserData);
    }

    protected void rptrVaceField_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                    //{
                    //    vmlBL.populateEthnicity(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                    //{
                    //    vmlBL.populateLanguage(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                    //{
                    //    vmlBL.populateCountry(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    //{
                    //    // vmlBL.populateCountry(ref ddl);
                    //    vmlBL.PopulateEnrollCdn(ref ddl);
                    //}
                    // maindiv.Controls.Add(ddl);
                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                //******01/05/2010*********
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                    control.ID = "uc";
                    maindiv.Controls.Add(control);
                }

            }
            //else if (hdnDefCus.Value.ToString().Trim() == "C")
            //{
            //    if (hdnFieldType.Value.ToString() == "1")
            //    {
            //        TextBox txt = new TextBox();
            //        txt.ID = "txt";
            //        txt.Width = 100;

            //        maindiv.Controls.Add(txt);

            //    }
            //    if (hdnFieldType.Value.ToString() == "2")
            //    {
            //        CheckBoxList chk = new CheckBoxList();
            //        chk.ID = "chk";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrchk(ref chk);
            //        chk.RepeatDirection = RepeatDirection.Horizontal;
            //        maindiv.Controls.Add(chk);
            //    }
            //    if (hdnFieldType.Value.ToString() == "3")
            //    {
            //        RadioButtonList rdb = new RadioButtonList();
            //        rdb.ID = "rdb";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrbtn(ref rdb);
            //        rdb.RepeatDirection = RepeatDirection.Horizontal;

            //        maindiv.Controls.Add(rdb);
            //    }
            //    if (hdnFieldType.Value.ToString() == "4")
            //    {
            //        DropDownList ddl = new DropDownList();
            //        ddl.ID = "ddl";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicddl(ref ddl);
            //        ddl.AutoPostBack = false;
            //        maindiv.Controls.Add(ddl);

            //    }
            //    if (hdnFieldType.Value.ToString() == "5")
            //    {
            //        Label lbl = new Label();
            //        lbl.ID = "lbl";
            //        StudentBL stbl2 = new StudentBL();

            //        maindiv.Controls.Add(lbl);
            //    }
            //}

            //if (hdnDefCus.Value.ToString().Trim() == "D")
            //{
            //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
            //    {
            //        e.Item.Visible = false;
            //    }
            //}
            // fieldid++;

        }
        catch { }


    }

    protected void imgbtnImmuEdit_Click(object sender, ImageClickEventArgs e)
    {

        // StudentBL schoolcategory = new StudentBL();

        for (int i = 0; i < GVImmunization.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GVImmunization.Rows[i].FindControl("chkGVImmunization");
            if (chk.Checked)
            {
                Label lblImmunizationType = (Label)GVImmunization.Rows[i].FindControl("lblImmunizationType");
                Label lblDate = (Label)GVImmunization.Rows[i].FindControl("lblDateGVImmunization");
                Label lblComments = (Label)GVImmunization.Rows[i].FindControl("lblCommentsGVImmunization");
                txtdateEdit.Text = lblDate.Text.ToString();
                txtcommentsEdit.Text = lblComments.Text.ToString();
                ImmuRowId = i;
            }
        }

        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");

            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }



     

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        // PopulateMedicalInfoFieldData();
        // PopulateVaccinationFieldData();

        ModalPopupExtender1.Enabled = true;
        ModalPopupExtender1.Show();


    }

    protected void ibtnAlertEdit_Click(object sender, ImageClickEventArgs e)
    {

        // StudentBL schoolcategory = new StudentBL();

        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }

        for (int i = 0; i < GVMedicalAlert.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GVMedicalAlert.Rows[i].FindControl("chkGVMedicalAlert");
            if (chk.Checked)
            {
                Label lblMedicalAlert = (Label)GVMedicalAlert.Rows[i].FindControl("lblMedicalAlert");
                txtAlertsEdit.Text = lblMedicalAlert.Text.ToString();
                AlertRowId = i;

            }
        }


        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");

            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }



        // PopulateVccinationGridview();

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        // PopulateMedicalInfoFieldData();
        // PopulateVaccinationFieldData();

        ModalPopupExtender6.Enabled = true;
        ModalPopupExtender6.Show();


    }

    protected void ibtnNursevisitEdit_Click(object sender, ImageClickEventArgs e)
    {

        //   StudentBL schoolcategory = new StudentBL();

        for (int i = 0; i < GVNurseVisitRec.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GVNurseVisitRec.Rows[i].FindControl("chkGVNurseVisitRec");
            if (chk.Checked)
            {
                Label lblDate = (Label)GVNurseVisitRec.Rows[i].FindControl("lblDate");
                Label lblTimeIn = (Label)GVNurseVisitRec.Rows[i].FindControl("lblTimeIn");
                Label lblTimeOut = (Label)GVNurseVisitRec.Rows[i].FindControl("lblTimeOut");
                Label lblReason = (Label)GVNurseVisitRec.Rows[i].FindControl("lblReason");
                Label lblResult = (Label)GVNurseVisitRec.Rows[i].FindControl("lblResult");
                Label lblComments = (Label)GVNurseVisitRec.Rows[i].FindControl("lblComments");
                txtNurseVisitDateEdit.Text = lblDate.Text.ToString();
                txtTimeInEdit.Text = lblTimeIn.Text.ToString();
                txtTimeOutEdit.Text = lblTimeOut.Text.ToString();
                txtReasonEdit.Text = lblReason.Text.ToString();
                txtResultEdit.Text = lblResult.Text.ToString();
                txtNurseCommentsEdit.Text = lblComments.Text.ToString();
                NurseVisitRowId = i;
            }
        }

        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
        else
        {
            DataTable dtImmuDetails = new DataTable();
            dtImmuDetails.Columns.Add("Type");
            dtImmuDetails.Columns.Add("Date");
            dtImmuDetails.Columns.Add("Comment");
            dtImmuDetails.Columns.Add("Typevalue");
            DataRow dr = dtImmuDetails.NewRow();
            dtImmuDetails.Rows.Add(dr);
            GVImmunization.DataSource = dtImmuDetails;
            GVImmunization.DataBind();

        }
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
        else
        {
            DataTable dtAlertDetails = new DataTable();
            dtAlertDetails.Columns.Add("Alert");

            DataRow dr = dtAlertDetails.NewRow();
            dtAlertDetails.Rows.Add(dr);
            GVMedicalAlert.DataSource = dtAlertDetails;
            GVMedicalAlert.DataBind();


        }
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }
        else
        {
            DataTable dtNurseVisitDetails = new DataTable();
            dtNurseVisitDetails.Columns.Add("Date");
            dtNurseVisitDetails.Columns.Add("TimeIn");
            dtNurseVisitDetails.Columns.Add("TimeOut");
            dtNurseVisitDetails.Columns.Add("Reason");
            dtNurseVisitDetails.Columns.Add("Result");
            dtNurseVisitDetails.Columns.Add("Comments");
            DataRow dr = dtNurseVisitDetails.NewRow();
            dtNurseVisitDetails.Rows.Add(dr);
            GVNurseVisitRec.DataSource = dtNurseVisitDetails;
            GVNurseVisitRec.DataBind();

        }



        // PopulateVccinationGridview();

        //DataTable dtMedicalInfo = new DataTable();
        //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        //rptMedicalInfo.DataSource = dtMedicalInfo;
        //rptMedicalInfo.DataBind();

        //DataTable dtVcea = new DataTable();
        //dtVcea = schoolcategory.GetVaccinationFields();
        //rptrVaceField.DataSource = dtVcea;
        //rptrVaceField.DataBind();

        // PopulateMedicalInfoFieldData();
        // PopulateVaccinationFieldData();

        ModalPopupExtender7.Enabled = true;
        ModalPopupExtender7.Show();


    }

    protected void btnAlertcancelEdit_Click(object sender, EventArgs e)
    {
        ModalPopupExtender6.Enabled = false;
        ModalPopupExtender6.Show();
        btnPrev.Visible = true;

    }

    protected void btnImmuCancelEdit_Click(object sender, EventArgs e)
    {
       
        ModalPopupExtender1.Enabled = false;
        ModalPopupExtender1.Show();
        btnPrev.Visible = true;

    }

    protected void ibtnVaceEdit_Click(object sender, ImageClickEventArgs e)
    {

        //// StudentBL schoolcategory = new StudentBL();
        //IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        //DataTable dtVaccination = new DataTable();
        //dtVaccination.Columns.Add("Vaccination_Code");
        //dtVaccination.Columns.Add("Vaccination_Name");
        //dtVaccination.Columns.Add("Vaccination_Date");
        //dtVaccination.Columns.Add("Vaccination_Expiry_Date");
        //dtVaccination.Columns.Add("Waiver");

        //DataRow drvaccination = dtVaccination.NewRow();
        //for (int i = 0; i < GVVccination.Rows.Count; i++)
        //{
        //    CheckBox chk = (CheckBox)GVVccination.Rows[i].FindControl("chk");
        //    if (chk.Checked)
        //    {
        //        Label lblVaccinationCode = (Label)GVVccination.Rows[i].FindControl("lblVaccinationCode");
        //        Label lblVaccinationName = (Label)GVVccination.Rows[i].FindControl("lblVaccinationName");
        //        Label lblVaccinationDate = (Label)GVVccination.Rows[i].FindControl("lblVaccinationDate");
        //        Label lblVaccinationExpiryDate = (Label)GVVccination.Rows[i].FindControl("lblVaccinationExpiryDate");
        //        Label lblWaiver = (Label)GVVccination.Rows[i].FindControl("lblWaiver");
        //        drvaccination[0] = lblVaccinationCode.Text.ToString();
        //        drvaccination[1] = lblVaccinationName.Text.ToString();
        //        drvaccination[2] = lblVaccinationDate.Text.ToString();
        //        drvaccination[3] = lblVaccinationExpiryDate.Text.ToString();
        //        drvaccination[4] = lblWaiver.Text.ToString();
        //        NurseVisitRowId = i;
        //    }
        //}

        //dtVaccination.Rows.Add(drvaccination);
        //Session.Add("Vaccination", dtVaccination);
        //DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        //if (SessiondtImmu != null)
        //{
        //    GVImmunization.DataSource = SessiondtImmu;
        //    GVImmunization.DataBind();
        //}
        //else
        //{
        //    DataTable dtImmuDetails = new DataTable();
        //    dtImmuDetails.Columns.Add("Type");
        //    dtImmuDetails.Columns.Add("Date");
        //    dtImmuDetails.Columns.Add("Comment");
        //    dtImmuDetails.Columns.Add("Typevalue");
        //    DataRow dr = dtImmuDetails.NewRow();
        //    dtImmuDetails.Rows.Add(dr);
        //    GVImmunization.DataSource = dtImmuDetails;
        //    GVImmunization.DataBind();

        //}
        //DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        //if (SessiondtAlert != null)
        //{
        //    GVMedicalAlert.DataSource = SessiondtAlert;
        //    GVMedicalAlert.DataBind();
        //}
        //else
        //{
        //    DataTable dtAlertDetails = new DataTable();
        //    dtAlertDetails.Columns.Add("Alert");

        //    DataRow dr = dtAlertDetails.NewRow();
        //    dtAlertDetails.Rows.Add(dr);
        //    GVMedicalAlert.DataSource = dtAlertDetails;
        //    GVMedicalAlert.DataBind();


        //}
        //DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        //if (SessiondtNurseVisit != null)
        //{
        //    GVNurseVisitRec.DataSource = SessiondtNurseVisit;
        //    GVNurseVisitRec.DataBind();
        //}
        //else
        //{
        //    DataTable dtNurseVisitDetails = new DataTable();
        //    dtNurseVisitDetails.Columns.Add("Date");
        //    dtNurseVisitDetails.Columns.Add("TimeIn");
        //    dtNurseVisitDetails.Columns.Add("TimeOut");
        //    dtNurseVisitDetails.Columns.Add("Reason");
        //    dtNurseVisitDetails.Columns.Add("Result");
        //    dtNurseVisitDetails.Columns.Add("Comments");
        //    DataRow dr = dtNurseVisitDetails.NewRow();
        //    dtNurseVisitDetails.Rows.Add(dr);
        //    GVNurseVisitRec.DataSource = dtNurseVisitDetails;
        //    GVNurseVisitRec.DataBind();

        //}





        ////DataTable dtMedicalInfo = new DataTable();
        ////dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
        ////rptMedicalInfo.DataSource = dtMedicalInfo;
        ////rptMedicalInfo.DataBind();

        ////DataTable dtVcea = new DataTable();
        ////dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(Convert.ToInt32(Session["SchoolID"]), Convert.ToInt32(hdnCatId.Value));
        ////rptrVaceFieldEdit.DataSource = dtVcea;
        ////rptrVaceFieldEdit.DataBind();

        ////// PopulateMedicalInfoFieldData();
        ////PopulateVaccinationFieldData();
        //PopulateVccinationGridview();

        //ModalPopupExtender8.Enabled = true;
        //ModalPopupExtender8.Show();


    }

    protected void btnNurseVisitCancelEdit_Click(object sender, EventArgs e)
    {
        ModalPopupExtender7.Enabled = false;
        ModalPopupExtender7.Show();
        btnPrev.Visible = true;

    }

    protected void btnvcciCancelEdit_Click(object sender, EventArgs e)
    {
        ModalPopupExtender8.Enabled = false;
        ModalPopupExtender8.Show();
        btnPrev.Visible = true;

    }


    protected void rptrVaceFieldEdit_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                    //{
                    //    vmlBL.populateEthnicity(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                    //{
                    //    vmlBL.populateLanguage(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                    //{
                    //    vmlBL.populateCountry(ref ddl);
                    //}
                    //if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    //{
                    //    // vmlBL.populateCountry(ref ddl);
                    //    vmlBL.PopulateEnrollCdn(ref ddl);
                    //}
                    // maindiv.Controls.Add(ddl);
                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    //  StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                //******01/05/2010***********
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                    control.ID = "uc";
                    maindiv.Controls.Add(control);
                }

            }
            //else if (hdnDefCus.Value.ToString().Trim() == "C")
            //{
            //    if (hdnFieldType.Value.ToString() == "1")
            //    {
            //        TextBox txt = new TextBox();
            //        txt.ID = "txt";
            //        txt.Width = 100;

            //        maindiv.Controls.Add(txt);

            //    }
            //    if (hdnFieldType.Value.ToString() == "2")
            //    {
            //        CheckBoxList chk = new CheckBoxList();
            //        chk.ID = "chk";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrchk(ref chk);
            //        chk.RepeatDirection = RepeatDirection.Horizontal;
            //        maindiv.Controls.Add(chk);
            //    }
            //    if (hdnFieldType.Value.ToString() == "3")
            //    {
            //        RadioButtonList rdb = new RadioButtonList();
            //        rdb.ID = "rdb";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicrbtn(ref rdb);
            //        rdb.RepeatDirection = RepeatDirection.Horizontal;

            //        maindiv.Controls.Add(rdb);
            //    }
            //    if (hdnFieldType.Value.ToString() == "4")
            //    {
            //        DropDownList ddl = new DropDownList();
            //        ddl.ID = "ddl";
            //        vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
            //        vmlBL.populatedynamicddl(ref ddl);
            //        ddl.AutoPostBack = false;
            //        maindiv.Controls.Add(ddl);

            //    }
            //    if (hdnFieldType.Value.ToString() == "5")
            //    {
            //        Label lbl = new Label();
            //        lbl.ID = "lbl";
            //        StudentBL stbl2 = new StudentBL();

            //        maindiv.Controls.Add(lbl);
            //    }
            //}

            //if (hdnDefCus.Value.ToString().Trim() == "D")
            //{
            //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
            //    {
            //        e.Item.Visible = false;
            //    }
            //}
            // fieldid++;

        }
        catch { }


    }

    protected void PopulateVaccinationFieldData()
    {
        try
        {

            string PrevSessionTable = "Vaccination";
            DataTable VaccinationDataFromSession = (DataTable)Session[PrevSessionTable];

            if (VaccinationDataFromSession != null)
            {
                int v = 0;

                for (int i = 0; i <= rptrVaceFieldEdit.Items.Count - 1; i++)
                {

                    TextBox txtfieldvalue = (TextBox)rptrVaceFieldEdit.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = VaccinationDataFromSession.Rows[0][i].ToString();
                    }

                    DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceFieldEdit.Items[i].FindControl("uc");
                    if (uc != null)
                    {
                        uc.Value = VaccinationDataFromSession.Rows[0][i].ToString();

                    }
                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void btnAlertUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            // StudentBL schoolcategory = new StudentBL();
            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
            if (SessiondtAlert != null)
            {
                SessiondtAlert.Rows[AlertRowId]["Alert"] = txtAlertsEdit.Text.ToString();

                GVMedicalAlert.DataSource = SessiondtAlert;
                GVMedicalAlert.DataBind();
                Session.Add("AlertTable", SessiondtAlert);
            }


            //  ModalPopupExtender8.Enabled = true;
            // ModalPopupExtender8.Show();
            // PopulateMedicalInfoFieldData();
            // PopulateVccinationGridview();
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
         
            ModalPopupExtender6.Enabled = false;
            ModalPopupExtender6.Show();
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }

    protected void btnImmuUpdate_Click(object sender, EventArgs e)
    {
        try
        {

            // StudentBL schoolcategory = new StudentBL();
            DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
            if (SessiondtImmu != null)
            {
                SessiondtImmu.Rows[ImmuRowId]["Type"] = ddlImmunaizationEdit.SelectedItem.Value;
                SessiondtImmu.Rows[ImmuRowId]["Date"] = txtdateEdit.Text.ToString();
                SessiondtImmu.Rows[ImmuRowId]["Comment"] = txtcommentsEdit.Text.ToString();

                GVImmunization.DataSource = SessiondtImmu;
                GVImmunization.DataBind();
                Session.Add("ImmuTable", SessiondtImmu);
            }

            //  PopulateMedicalInfoFieldData();
            //   PopulateVccinationGridview();
          
            ModalPopupExtender1.Enabled = false;
            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }


    protected void btnNurseVisitUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            //StudentBL schoolcategory = new StudentBL();
            DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
            if (SessiondtNurseVisit != null)
            {

                SessiondtNurseVisit.Rows[NurseVisitRowId]["Date"] = txtNurseVisitDateEdit.Text.ToString();
                SessiondtNurseVisit.Rows[NurseVisitRowId]["TimeIn"] = txtTimeInEdit.Text.ToString();
                SessiondtNurseVisit.Rows[NurseVisitRowId]["TimeOut"] = txtTimeOutEdit.Text.ToString();
                SessiondtNurseVisit.Rows[NurseVisitRowId]["Reason"] = txtReasonEdit.Text.ToString();
                SessiondtNurseVisit.Rows[NurseVisitRowId]["Result"] = txtResultEdit.Text.ToString();
                SessiondtNurseVisit.Rows[NurseVisitRowId]["Comments"] = txtNurseCommentsEdit.Text.ToString();


                GVNurseVisitRec.DataSource = SessiondtNurseVisit;
                GVNurseVisitRec.DataBind();
                Session.Add("NurseVisitTable", SessiondtNurseVisit);

            }

            //  PopulateMedicalInfoFieldData();
            //  PopulateVccinationGridview();

            //DataTable dtMedicalInfo = new DataTable();
            //dtMedicalInfo = schoolcategory.GetMedicalInfoFields();
            //rptMedicalInfo.DataSource = dtMedicalInfo;
            //rptMedicalInfo.DataBind();

            //DataTable dtVcea = new DataTable();
            //dtVcea = schoolcategory.GetVaccinationFields();
            //rptrVaceField.DataSource = dtVcea;
            //rptrVaceField.DataBind();
            //btnPrev.Visible = true;
           
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }


    }

    protected void btnvcciUpdate_Click(object sender, EventArgs e)
    {
        DataTable SessiondtVaccination = (DataTable)Session["VaccinationForGrid"];
        if (SessiondtVaccination != null)
        {


            foreach (var C in panel_VaccinationEdit.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    Repeater rptrVaceField = ((Repeater)C);

                    for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
                    {
                        TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");

                        if (txtfieldvalue != null)
                        {
                            SessiondtVaccination.Rows[NurseVisitRowId][i] = txtfieldvalue.Text.ToString();
                        }

                    }

                }
            }

            //GVVccination.DataSource = SessiondtVaccination;
            //GVVccination.DataBind();
            //Session.Add("VaccinationForGrid", SessiondtVaccination);
        }

        ModalPopupExtender8.Enabled = false;


       
    }


    //protected void StoreVaccinationFieldDataIntoDatatable()
    //{

    //    DataTable SessiondtVaccination = (DataTable)Session["VaccinationForInsert"];
    //    if (SessiondtVaccination == null)
    //    {
    //        DataTable dtUserData = new DataTable();
    //        dtUserData.Columns.Add("Value");
    //        dtUserData.Columns.Add("FieldId");
    //        dtUserData.Columns.Add("FieldCatagory");


    //        foreach (var C in panel_Vaccination.Controls)
    //        {

    //            if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
    //            {

    //                for (int i = 0; i <= rptrVaceField.Items.Count - 1; i++)
    //                {
    //                    DataRow dr = dtUserData.NewRow();
    //                    TextBox txtfieldvalue = (TextBox)rptrVaceField.Items[i].FindControl("txt");
    //                    HiddenField hdnFieldId = (HiddenField)rptrVaceField.Items[i].FindControl("hdnFieldId");
    //                    DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceField.Items[i].FindControl("uc");
    //                    if (txtfieldvalue != null)
    //                    {
    //                        dr[0] = txtfieldvalue.Text.ToString();
    //                        dr[1] = hdnFieldId.Value.ToString();
    //                        txtfieldvalue.Text = "";
    //                    }
    //                    if (uc != null)
    //                    {
    //                        dr[0] = uc.Value.ToString();
    //                        dr[1] = hdnFieldId.Value.ToString();
    //                        uc.Value = "";
    //                    }

    //                    dtUserData.Rows.Add(dr);
                        
                        
    //                }
    //            }
    //        }
    //        string SessionTableName = "VaccinationForInsert";
    //        Session.Add(SessionTableName, dtUserData);
    //    }
    //    else
    //    {

    //        //*************2nd row problem

    //        //foreach (var C in panel_Vaccination.Controls)
    //        //{

    //        //    if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
    //        //    {

    //        //        for (int i = 0; i <= rptrVaceFieldEdit.Items.Count - 1; i++)
    //        //        {
    //        //            DataRow drvacc = SessiondtVaccination.NewRow();
    //        //            TextBox txtfieldvalue = (TextBox)rptrVaceFieldEdit.Items[i].FindControl("txt");
    //        //            HiddenField hdnFieldId = (HiddenField)rptrVaceFieldEdit.Items[i].FindControl("hdnFieldId");
    //        //            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceFieldEdit.Items[i].FindControl("uc");
    //        //            if (txtfieldvalue != null)
    //        //            {
    //        //                drvacc[0] = txtfieldvalue.Text.ToString();
    //        //                drvacc[1] = hdnFieldId.Value.ToString();
    //        //                txtfieldvalue.Text = "";
    //        //            }
    //        //            if (uc != null)
    //        //            {
    //        //                drvacc[0] = uc.Value.ToString();
    //        //                drvacc[1] = hdnFieldId.Value.ToString();
    //        //                uc.Value = "";
    //        //            }
    //        //            SessiondtVaccination.Rows.Add(drvacc);
    //        //        }
    //        //    }
    //        //}

    //        //Session.Add("VaccinationForInsert", SessiondtVaccination);
    //    }
    //}


    //Enrollemnt codes from here
    protected void rptrSchlInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentInfoBL StdInfo = new StudentInfoBL();
        try
        {
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            //Panel maindiv = (Panel)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            if (hdnDefCus.Value.ToString().Trim() == "D")
            {
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    txt.CssClass = "textbox2";
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;
                    maindiv.Controls.Add(chk);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    //RadioButtonList rdb = new RadioButtonList();
                    //rdb.ID = "rdb";
                    //vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
                    //if (Convert.ToInt32(hdnFieldId.Value) == 10)
                    //{
                    //    vmlBL.PopulateGender(ref rdb);
                    //}
                    //rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //maindiv.Controls.Add(rdb);
                }
                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";
                    maindiv.Controls.Add(ddl);
                    if (Convert.ToInt32(hdnFieldId.Value.ToString()) == 110)//Calender
                    {

                        //StudentBL schoolcategory = new StudentBL();
                        StudentListControl Stulistcont = new StudentListControl();
                        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        Stulistcont.populatecalender(ref ddl, SchoolID);
                    }

                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    RadioButtonList rdb = new RadioButtonList();
                    rdb.ID = "rdb";
                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                    // StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(rdb);
                    if (Convert.ToInt32(hdnFieldId.Value.ToString()) == 106)//Calender
                    {

                        //  StudentBL schoolcategory = new StudentBL();
                        StudentListControl stuliscont = new StudentListControl();
                        int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                        stuliscont.PopulateYesNo(ref rdb);
                    }
                }

                //****************************1/5/2010***********
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                    control.ID = "uc";
                    
                    maindiv.Controls.Add(control);
                }


            }
            if (hdnDefCus.Value.ToString().Trim() == "C")
            {
                //   StudentBL schoolcategory = new StudentBL();
                StudentListControl stuliscont = new StudentListControl();
                int ExtrafieldId = Convert.ToInt32(hdnFieldId.Value);
                if (hdnFieldType.Value.ToString() == "1")
                {
                    TextBox txt = new TextBox();
                    txt.ID = "txt";
                    txt.Width = 150;
                    txt.CssClass = "textbox2";
                    maindiv.Controls.Add(txt);
                    //e.Item.Controls.Add(txt);
                    // string t = txt.ID.ToString();

                }
                if (hdnFieldType.Value.ToString() == "2")
                {
                    CheckBoxList chk = new CheckBoxList();
                    chk.ID = "chk";
                    chk.RepeatDirection = RepeatDirection.Horizontal;


                    stuliscont.populatedynamicrchk(ref chk, ExtrafieldId);


                    maindiv.Controls.Add(chk);
                }

                if (hdnFieldType.Value.ToString() == "4")
                {
                    DropDownList ddl = new DropDownList();
                    ddl.ID = "ddl";
                    ddl.Width = 155;
                    ddl.CssClass = "textbox_date";



                    stuliscont.populatedynamicddl(ref ddl, ExtrafieldId);

                    maindiv.Controls.Add(ddl);


                }
                if (hdnFieldType.Value.ToString() == "5")
                {
                    Label lbl = new Label();
                    lbl.ID = "lbl";
                    //   StudentBL stbl2 = new StudentBL();
                    maindiv.Controls.Add(lbl);
                }
                if (hdnFieldType.Value.ToString() == "3")
                {
                    RadioButtonList rdb = new RadioButtonList();
                    rdb.ID = "rdb";
                    rdb.RepeatDirection = RepeatDirection.Horizontal;
                    //  StudentBL stbl2 = new StudentBL();



                    stuliscont.populatedynamicrbtn(ref rdb, ExtrafieldId);

                    maindiv.Controls.Add(rdb);

                }
                //****************************1/5/2010***********
                if (hdnFieldType.Value.ToString() == "6")
                {
                    var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                    control.ID = "uc";

                    maindiv.Controls.Add(control);
                }
            }

        }
        catch
        {

        }
    }


    protected void PopulateSchoolFieldData()
    {
        try
        {

            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");



            string PrevSessionTable = "SchoolInfo";
            DataTable SchoolInfoDataFromSession = (DataTable)Session[PrevSessionTable];

            if (SchoolInfoDataFromSession != null)
            {

                int v = 0;


                for (int i = 0; i <= rptrSchlInfo.Items.Count - 1; i++)
                {
                    HiddenField hdnFieldId = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnFieldId");
                    TextBox txtfieldvalue = (TextBox)rptrSchlInfo.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptrSchlInfo.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {
                        ddlfieldvalue.Items.FindByValue(SchoolInfoDataFromSession.Rows[v][0].ToString()).Selected = true;
                    }
                    RadioButtonList rdb = (RadioButtonList)rptrSchlInfo.Items[i].FindControl("rdb");
                    if (rdb != null)
                    {
                        for (int r = 0; r < rdb.Items.Count; r++)
                        {
                            if (rdb.Items[r].Value == SchoolInfoDataFromSession.Rows[v][0].ToString())
                            {
                                rdb.Items[r].Selected = true;
                            }
                        }
                    }

                    //**********01/05/2010**********
                    DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
                    if (uc != null)
                    {

                        uc.Value = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }

                    v++;

                }
            }
            else
            {

                // StudentEditInfoBL StFieldValue = new StudentEditInfoBL();
                OpenSISWCFServiceStudentEditClient StFieldValue = new OpenSISWCFServiceStudentEditClient();
                //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int CatId = Convert.ToInt32(hdnCatId.Value.ToString());
                int StudentID = Convert.ToInt32(hdnStudentId.Value);

                DataTable dtFieldvalue = StFieldValue.PopulateSchoolFieldValueStudentEdit(CatId, StudentID, SchoolID);


                for (int i = 0; i < dtFieldvalue.Rows.Count; i++)
                {
                    DataRow dr = dtUserData.NewRow();


                    dr["Value"] = dtFieldvalue.Rows[i]["value"].ToString();
                    dr["FieldId"] = dtFieldvalue.Rows[i]["field_id"].ToString();
                    dr["FieldCatagory"] = dtFieldvalue.Rows[i]["field_category"].ToString();


                    dtUserData.Rows.Add(dr);


                }



                SchoolInfoDataFromSession = dtUserData;





                int v = 0;


                for (int i = 0; i <= rptrSchlInfo.Items.Count - 1; i++)
                {
                    HiddenField hdnFieldId = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnFieldId");
                    TextBox txtfieldvalue = (TextBox)rptrSchlInfo.Items[i].FindControl("txt");

                    if (txtfieldvalue != null)
                    {
                        txtfieldvalue.Text = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }

                    DropDownList ddlfieldvalue = (DropDownList)rptrSchlInfo.Items[i].FindControl("ddl");
                    if (ddlfieldvalue != null)
                    {
                        ddlfieldvalue.Items.FindByValue(SchoolInfoDataFromSession.Rows[v][0].ToString()).Selected = true;
                    }
                    RadioButtonList rdb = (RadioButtonList)rptrSchlInfo.Items[i].FindControl("rdb");
                    if (rdb != null)
                    {
                        for (int r = 0; r < rdb.Items.Count; r++)
                        {
                            if (rdb.Items[r].Value == SchoolInfoDataFromSession.Rows[v][0].ToString())
                            {
                                rdb.Items[r].Selected = true;
                            }
                        }
                    }
                    //****01/05/2010*********
                    DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
                    if (uc != null)
                    {

                        uc.Value = SchoolInfoDataFromSession.Rows[v][0].ToString();
                    }


                    v++;

                }

            }


        }
        catch (Exception ex)
        {
            string Ex = ex.ToString();
        }

    }

    protected void StoreSchoolInfoDataIntoDatatable()
    {
        //try
        //{


        DataTable dtUserData = new DataTable();

        dtUserData.Columns.Add("Value");
        dtUserData.Columns.Add("FieldId");
        dtUserData.Columns.Add("FieldCatagory");

        for (int i = 0; i <= rptrSchlInfo.Items.Count - 1; i++)
        {
            DataRow dr = dtUserData.NewRow();

            TextBox txtfieldvalue = (TextBox)rptrSchlInfo.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnFieldId");
            HiddenField hdnDefCus = (HiddenField)rptrSchlInfo.Items[i].FindControl("hdnDefCus");
            if (txtfieldvalue != null)
            {
                dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr[2] = hdnCatId.Value.ToString();
                //dr[3] = hdnDefCus.Value.ToString();
                //dtUserData.Rows.Add(dr);
            }
            DropDownList ddlfieldvalue = (DropDownList)rptrSchlInfo.Items[i].FindControl("ddl");
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {
                    dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();

                }

            }
            RadioButtonList rdb = (RadioButtonList)rptrSchlInfo.Items[i].FindControl("rdb");
            if (rdb != null)
            {
                for (int r = 0; r < rdb.Items.Count; r++)
                {
                    if (rdb.Items[r].Selected)
                    {
                        dr[0] = rdb.SelectedItem.Value.ToString();
                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr[2] = hdnCatId.Value.ToString();
                        //dr[3] = hdnDefCus.Value.ToString();
                        //dtUserData.Rows.Add(dr);
                    }

                }

            }
            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSchlInfo.Items[i].FindControl("uc");
            if (uc != null)
            {
                dr[0] = uc.Value.ToString();

            }
            dr[1] = hdnFieldId.Value.ToString();

            dr[2] = hdnDefCus.Value.ToString();
            dtUserData.Rows.Add(dr);

        }




        string SessionTableName = "SchoolInfo";
        Session.Add(SessionTableName, dtUserData);


        //}
        //catch (Exception ex)
        //    {
        //        string EX = ex.ToString();
        //    }



    }

    protected void ibtnEnrInfo_Click(object sender, ImageClickEventArgs e)
    {

        rptrSchlInfo.Visible = true;
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        if (SessiondtEnrol != null)
        {
            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
        else
        {
            int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            DataTable dtEnrol = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);


            gvEnrInfo.DataSource = dtEnrol;
            gvEnrInfo.DataBind();
        }


        // PopulateVccinationGridview();
        StudentListControl Stuliscont = new StudentListControl();
        Stuliscont.PopulateEnrollCdn(ref ddlExitCode);


        PopulateSchoolFieldData();
        // PopulateVaccinationFieldData();

        ModalPopupExtender9.Enabled = true;
        ModalPopupExtender9.Show();


    }

    protected void ibtnDelEnrInfo_Click(object sender, ImageClickEventArgs e)
    {
        hdnUpdate.Value = "Update";
        rptrSchlInfo.Visible = true;
        rptrSchlInfo.Visible = true;
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();

        int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        StoreSchoolInfoDataIntoDatatable();
        DataTable dtEnrol = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);
        for (int i = 0; i < gvEnrInfo.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)gvEnrInfo.Rows[i].FindControl("chk");

            HiddenField hdnenrid = (HiddenField)gvEnrInfo.Rows[i].FindControl("hdnenrid");
            if (chk.Checked)
            {

                hdnEnrollId.Value = hdnenrid.Value;
                int EnrollId = Convert.ToInt32(hdnEnrollId.Value);
                if (SessiondtEnrol != null)
                {
                    if (SessiondtEnrol.Columns.Contains("temp"))
                    {
                        for (int j = 0; j < SessiondtEnrol.Rows.Count; j++)
                        {
                            if (SessiondtEnrol.Rows[j]["Std_Enr_Id"].ToString() == hdnEnrollId.Value)
                            {
                                if (SessiondtEnrol.Rows[j]["temp"].ToString() == "Add")
                                {
                                    SessiondtEnrol.Rows[j].Delete();
                                    gvEnrInfo.DataSource = SessiondtEnrol;
                                    gvEnrInfo.DataBind();
                                  //  Session.Add("Enroltable", SessiondtEnrol);

                                }
                                else
                                {

                                    SessiondtEnrol.Rows[j].Delete();
                                    SessiondtEnrol.AcceptChanges();
                                    //SessiondtEnrol.GetChanges();
                                    EnrollId = Convert.ToInt32(hdnEnrollId.Value);
                                    schoolcategory.DeleteEnrollmentStudentBusiness(EnrollId);
                                    //DataTable dtEnrolaftersesiondel = schoolcategory.Getstudentschoolenroll();
                                    //SessiondtEnrol.Merge(dtEnrolaftersesiondel);
                                    gvEnrInfo.DataSource = SessiondtEnrol;
                                    gvEnrInfo.DataBind();
                                   // Session.Add("Enroltable", SessiondtEnrol);
                                }

                            }


                        }

                    }
                    else
                    {
                        for (int j = 0; j < SessiondtEnrol.Rows.Count; j++)
                        {
                            if (SessiondtEnrol.Rows[j]["Std_Enr_Id"].ToString() == hdnEnrollId.Value)
                            {



                                EnrollId = Convert.ToInt32(hdnEnrollId.Value);
                                schoolcategory.DeleteEnrollmentStudentBusiness(EnrollId);
                                DataTable dtEnrolaftersesiondel = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID); gvEnrInfo.DataSource = dtEnrolaftersesiondel;
                                gvEnrInfo.DataBind();
                                Session.Add("Enroltable", dtEnrolaftersesiondel);


                            }


                        }
                    }


                }
                else
                {
                    schoolcategory.DeleteEnrollmentStudentBusiness(EnrollId);
                    DataTable dtEnrolafterdel = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);
                    gvEnrInfo.DataSource = dtEnrolafterdel;
                    gvEnrInfo.DataBind();

                }




            }


        }
        PopulateSchoolFieldData();


    }

    protected void ibtnEditEnrInfo_Click(object sender, ImageClickEventArgs e)
    {
        hdnUpdate.Value = "Update";

        rptrSchlInfo.Visible = true;
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        StudentListControl stulistcont = new StudentListControl();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        StoreSchoolInfoDataIntoDatatable();

        for (int i = 0; i < gvEnrInfo.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)gvEnrInfo.Rows[i].FindControl("chk");
            Label lblAttStrtDate = (Label)gvEnrInfo.Rows[i].FindControl("lblAttStrtDate");
            Label lblExitDate = (Label)gvEnrInfo.Rows[i].FindControl("lblExitDate");
            HiddenField hdnenrcode = (HiddenField)gvEnrInfo.Rows[i].FindControl("hdnenrcode");
            Label lblExitReason = (Label)gvEnrInfo.Rows[i].FindControl("lblExitReason");
            Label lblStrtCond = (Label)gvEnrInfo.Rows[i].FindControl("lblStrtCond");
            HiddenField hdnenrid = (HiddenField)gvEnrInfo.Rows[i].FindControl("hdnenrid");
            if (chk.Checked)
            {
                stulistcont.PopulateEnrollCdn(ref ddlEditExitCode);
                hdnEnrollId.Value = hdnenrid.Value;
                txtEditAttStrtDate.Text = lblAttStrtDate.Text;
                txtEditExitdate.Text = lblExitDate.Text;
                txtEditExitreason.Text = lblExitReason.Text;
                txtEditStartCond.Text = lblStrtCond.Text;

                ddlEditExitCode.Items.FindByValue(hdnenrcode.Value).Selected = true;


                mdlpopEditEnrll.Enabled = true;
                mdlpopEditEnrll.Show();

            }


        }
        PopulateSchoolFieldData();
        //hdnUpdate.Value = "N.U";

    }

    protected void btnSaveEnrInfo_Click(object sender, EventArgs e)
    {
        btnPrev.Visible = true;
        ibtnEnrInfo.Visible = true;

        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        StudentListControl stulistcont = new StudentListControl();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        SISInstall SISInstall = new SISInstall();
        OpenSISWCFServiceSchoolDetailsClient schoolAdd = new OpenSISWCFServiceSchoolDetailsClient();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();

        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }

        DataTable dtEnrol = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);

        if (SessiondtEnrol != null)
        {

            //SessiondtEnrol.Columns.Add("temp");

            if (!SessiondtEnrol.Columns.Contains("temp"))
            {
                SessiondtEnrol.Columns.Add("temp");

            }

            DataRow dr = SessiondtEnrol.NewRow();


            DataView dv = SessiondtEnrol.DefaultView;

            dv.Sort = "Std_Enr_Id";


            //int enrid = Convert.ToInt32(dv[dv.Count - 1].Row["Std_Enr_Id"].ToString());
            int enrid = 0;
            if (SessiondtEnrol.Rows.Count > 0)
            {
                //if (dv[dv.Count - 1].Row["Std_Enr_Id"].ToString() != "")
                //{
                    enrid = Convert.ToInt32(dv[dv.Count - 1].Row["Std_Enr_Id"].ToString());
                //}
            }


            dr["Std_Enr_Id"] = enrid + 1;

            DateTime date1 = Convert.ToDateTime(txtAttStrtDate.Text.ToString());
            DateTime date2 = Convert.ToDateTime(txtAttStrtDate.Text.ToString());

            //dr["Enr_Start_Date"] = date1.ToString(SISInstall.CalenderDateFormat);
            //dr["Enr_End_Date"] = date2.ToString(SISInstall.CalenderDateFormat);

            dr["Enr_Start_Date"] = txtAttStrtDate.Text.ToString();
            dr["Enr_End_Date"] = txtExitdate.Text.ToString();

            dr["enrollname"] = ddlExitCode.SelectedItem.Text;
            dr["Exit_Reason"] = txtExitreason.Text.ToString();
            dr["Start_Condition"] = txtStartCond.Text.ToString();
            dr["Enr_Code_Id"] = ddlExitCode.SelectedItem.Value;
            dr["temp"] = "Add";


            txtAttStrtDate.Text = "";
            txtExitdate.Text = "";

            txtExitreason.Text = "";
            txtStartCond.Text = "";
            ddlExitCode.Items.Clear();

            SessiondtEnrol.Rows.Add(dr);

            Session.Add("Enroltable", SessiondtEnrol);

            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
        else
        {
            if (!dtEnrol.Columns.Contains("temp"))
            {
                dtEnrol.Columns.Add("temp");

            }

            DataRow dr = dtEnrol.NewRow();

            DataView dv = dtEnrol.DefaultView;
            dv.Sort = "Std_Enr_Id";

            int enrid = 0;
            if (dtEnrol.Rows.Count > 0)
            {
                enrid = Convert.ToInt32(dv[dv.Count - 1].Row["Std_Enr_Id"].ToString());
            }


            dr["Std_Enr_Id"] = enrid + 1;

            //DateTime date1 = Convert.ToDateTime(txtAttStrtDate.Text.ToString());
            //DateTime date2 = Convert.ToDateTime(txtAttStrtDate.Text.ToString());

            //dr["Enr_Start_Date"] = date1.ToString(SISInstall.CalenderDateFormat);
            //dr["Enr_End_Date"] = date2.ToString(SISInstall.CalenderDateFormat);

            dr["Enr_Start_Date"] = txtAttStrtDate.Text.ToString();
            dr["Enr_End_Date"] = txtExitdate.Text.ToString();

            dr["enrollname"] = ddlExitCode.SelectedItem.Text;
            dr["Exit_Reason"] = txtExitreason.Text.ToString();
            dr["Start_Condition"] = txtStartCond.Text.ToString();
            dr["Enr_Code_Id"] = ddlExitCode.SelectedItem.Value;
            dr["temp"] = "Add";


            txtAttStrtDate.Text = "";
            txtExitdate.Text = "";

            txtExitreason.Text = "";
            txtStartCond.Text = "";
            ddlExitCode.Items.Clear();

            dtEnrol.Rows.Add(dr);

            Session.Add("Enroltable", dtEnrol);

            gvEnrInfo.DataSource = dtEnrol;
            gvEnrInfo.DataBind();
        }

        PopulateSchoolFieldData();


    }
    protected void btnUpdateEnrInfo_Click(object sender, EventArgs e)
    {
        btnPrev.Visible = true;
        ibtnEnrInfo.Visible = true;

        //StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        int StudentID = Convert.ToInt32(hdnStudentId.Value.ToString());
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        SISInstall SISInstall = new SISInstall();
        OpenSISWCFServiceSchoolDetailsClient schoolAdd = new OpenSISWCFServiceSchoolDetailsClient();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();

        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }

        DataTable dtEnrol = schoolcategory.GetstudentschoolenrollStudentBusiness(StudentID, SchoolID);

        if (SessiondtEnrol != null)
        {


            for (int i = 0; i < SessiondtEnrol.Rows.Count; i++)
            {
                if (SessiondtEnrol.Rows[i]["Std_Enr_Id"].ToString() == hdnEnrollId.Value)
                {
                    DateTime date1 = Convert.ToDateTime(txtEditAttStrtDate.Text.ToString());
                    DateTime date2 = Convert.ToDateTime(txtEditExitdate.Text.ToString());



                    //SessiondtEnrol.Rows[i]["Enr_Start_Date"] = date1.ToString(SISInstall.CalenderDateFormat);
                    //SessiondtEnrol.Rows[i]["Enr_End_Date"] = date2.ToString(SISInstall.CalenderDateFormat);

                    SessiondtEnrol.Rows[i]["Enr_Start_Date"] = txtEditAttStrtDate.Text.ToString();
                    SessiondtEnrol.Rows[i]["Enr_End_Date"] = txtEditExitdate.Text.ToString();
                    SessiondtEnrol.Rows[i]["enrollname"] = ddlEditExitCode.SelectedItem.Text;
                    SessiondtEnrol.Rows[i]["Exit_Reason"] = txtEditExitreason.Text.ToString();
                    SessiondtEnrol.Rows[i]["Start_Condition"] = txtEditStartCond.Text.ToString();
                    SessiondtEnrol.Rows[i]["Enr_Code_Id"] = ddlEditExitCode.SelectedItem.Value;
                }
            }


            //SessiondtEnrol.Rows.Add(dr);

            //Session.Add("Enroltable", SessiondtEnrol);

            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
        else
        {

            for (int i = 0; i < dtEnrol.Rows.Count; i++)
            {
                if (dtEnrol.Rows[i]["Std_Enr_Id"].ToString() == hdnEnrollId.Value)
                {
                    DateTime date1 = Convert.ToDateTime(txtEditAttStrtDate.Text.ToString());
                    DateTime date2 = Convert.ToDateTime(txtEditExitdate.Text.ToString());

                    //SessiondtEnrol.Rows[i]["Enr_Start_Date"] = date1.ToString(SISInstall.CalenderDateFormat);
                    //SessiondtEnrol.Rows[i]["Enr_End_Date"] = date2.ToString(SISInstall.CalenderDateFormat);

                    dtEnrol.Rows[i]["Enr_Start_Date"] = txtEditAttStrtDate.Text.ToString();
                    dtEnrol.Rows[i]["Enr_End_Date"] = txtEditExitdate.Text.ToString();
                    dtEnrol.Rows[i]["enrollname"] = ddlEditExitCode.SelectedItem.Text;
                    dtEnrol.Rows[i]["Exit_Reason"] = txtEditExitreason.Text.ToString();
                    dtEnrol.Rows[i]["Start_Condition"] = txtEditStartCond.Text.ToString();
                    dtEnrol.Rows[i]["Enr_Code_Id"] = ddlEditExitCode.SelectedItem.Value;
                }
            }


            // dtEnrol.Rows.Add(dr);

            Session.Add("Enroltable", dtEnrol);

            gvEnrInfo.DataSource = dtEnrol;
            gvEnrInfo.DataBind();
        }

        PopulateSchoolFieldData();



    }


    protected void gvEnrInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        SISInstall SISinstall = new SISInstall();
        //SchoolBL schoolAdd = new SchoolBL();
        //InstallationBL InstallBL = new InstallationBL();
        OpenSISWCFServiceSchoolDetailsClient schoolAdd = new OpenSISWCFServiceSchoolDetailsClient();
        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
        StudentListControl Stuliscont = new StudentListControl();
        DataTable dtDateFormat = InstallBL.getdateformat();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISinstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }



        // StaffBL STABL = new StaffBL();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txtAttStrtDateEdit = (TextBox)e.Row.FindControl("txtAttStrtDateEdit");
            TextBox txtExitDateEdit = (TextBox)e.Row.FindControl("txtExitDateEdit");
            //TextBox txtExitReasonEdit=(TextBox)e.Row.FindControl("txtExitReasonEdit");
            //TextBox txtStrtCondEdit = (TextBox)e.Row.FindControl("txtStrtCondEdit");
            DropDownList ddlExitCodeEdit = (DropDownList)e.Row.FindControl("ddlExitCodeEdit");
            HiddenField hdnExitcode = (HiddenField)e.Row.FindControl("hdnExitcode");
            Label lblExitCodeEdit = (Label)e.Row.FindControl("lblExitCodeEdit");
            if (lblExitCodeEdit != null)
            {
                if (lblExitCodeEdit.Text == "")
                {
                    lblExitCodeEdit.Text = hdnExitcode.Value;
                }
            }
            if (ddlExitCodeEdit != null)
            {
                Stuliscont.PopulateEnrollCdn(ref ddlExitCodeEdit);
                HiddenField hdnExitcodeEdit = (HiddenField)e.Row.FindControl("hdnExitcodeEdit");
                ddlExitCodeEdit.Items.FindByText(hdnExitcodeEdit.Value).Selected = true;
            }
            //if (txtExitDateEdit.Text == "")
            //{
            //    //chk.Visible = false;
            //    ibtnEditEnrInfo.Visible = false;

            //}
            //else
            //{

            //    //chk.Visible = true;
            //    ibtnEditEnrInfo.Visible = true;

            //}
            if (txtAttStrtDateEdit != null)
            {
                if (txtAttStrtDateEdit.Text != "")
                {

                    DateTime certdate = DateTime.Parse(txtAttStrtDateEdit.Text);
                    txtAttStrtDateEdit.Text = certdate.Date.ToString(SISinstall.CalenderDateFormat);
                }
                if (txtExitDateEdit.Text != "")
                {
                    DateTime CertExpDate = DateTime.Parse(txtExitDateEdit.Text);
                    txtExitDateEdit.Text = CertExpDate.Date.ToString(SISinstall.CalenderDateFormat);
                }
            }
            //if (ddlExitCodeEdit.SelectedItem.Value != "0")
            //{

            //}


            //DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
            //for (int i = 0; i < SessiondtEnrol.Rows.Count; i++)
            //{
            //    SessiondtEnrol.Rows[i]["Enr_Start_Date"] = txtAttStrtDateEdit.Text.ToString();
            //    SessiondtEnrol.Rows[i]["Enr_End_Date"] = txtExitDateEdit.Text.ToString();
            //    SessiondtEnrol.Rows[i]["enrollname"] = ddlExitCodeEdit.SelectedItem.Text;
            //    SessiondtEnrol.Rows[i]["Exit_Reason"] = txtExitReasonEdit.Text.ToString();
            //    SessiondtEnrol.Rows[i]["Start_Condition"] = txtStrtCondEdit.Text.ToString();
            //    SessiondtEnrol.Rows[i]["Enr_Code_Id"] = ddlExitCodeEdit.SelectedItem.Value;
            //    SessiondtEnrol.AcceptChanges();
            //}
            //Session.Add("Enroltable", SessiondtEnrol);
            
        }
    }


    //**********
    protected void imgbtnAddSpecial_Click(object sender, ImageClickEventArgs e)
    {
        //=== PopulateSpecialFields();

        mdlAddSpec.Enabled = true;
        mdlAddSpec.Show();
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    protected void imgbtnAddGifted_Click(object sender, ImageClickEventArgs e)
    {
        //== PopulateGiftedFields();
        mdlGiftProg.Enabled = true;
        mdlGiftProg.Show();
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    protected void btnSaveSpec_Click(object sender, EventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        int SchoolID = Convert.ToInt32(Session["SchoolID"]);

        //schoolcategory.SchoolID = 
        DataTable SessiondtSpecialEdu = (DataTable)Session["SpecialEduForInsert"];
        if (SessiondtSpecialEdu == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");
            dtUserData.Columns.Add("FieldName");
            //dtUserData.Columns.Add("Category");
            dtUserData.Columns.Add("Cat_Id");
            dtUserData.Columns.Add("FieldType");

            foreach (var C in pnlAddSpec.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrSpecial.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrSpecial.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrSpecial.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldType");
                        if (txtfieldvalue != null)
                        {
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }

                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSpecial.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }


                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();

                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    //dr[1] = hdnFieldId.Value.ToString();

                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString();
                                }

                            }

                        }
                        dr["Cat_Id"] = hdnCatId.Value.ToString();
                        dtUserData.Rows.Add(dr);
                    }
                }
            }






            string SessionTableName = "SpecialEduForInsert";
            Session.Add(SessionTableName, dtUserData);



            rptrSpecEdu.DataSource = dtUserData;
            rptrSpecEdu.DataBind();




        }
        else
        {
            foreach (var C in pnlAddSpec.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrSpecial.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtSpecialEdu.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrSpecial.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrSpecial.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrSpecial.Items[i].FindControl("hdnFieldType");
                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }

                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSpecial.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString();
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString();
                                }

                            }

                        }
                        dr["Cat_Id"] = hdnCatId.Value.ToString();
                        SessiondtSpecialEdu.Rows.Add(dr);
                    }
                }
            }




            Session.Add("SpecialEduForInsert", SessiondtSpecialEdu);
            rptrSpecEdu.DataSource = SessiondtSpecialEdu;
            rptrSpecEdu.DataBind();
        }

        PopulateGiftValue();

    }

    protected void btnSaveGift_Click(object sender, EventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
        if (SessiondtGift == null)
        {
            DataTable dtUserData = new DataTable();
            dtUserData.Columns.Add("Value");
            dtUserData.Columns.Add("FieldId");
            dtUserData.Columns.Add("FieldCatagory");
            dtUserData.Columns.Add("FieldName");
            //dtUserData.Columns.Add("Category");
            dtUserData.Columns.Add("Cat_Id");
            dtUserData.Columns.Add("FieldType");
            foreach (var C in pnlAddGiftProg.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrGiftforadd.Items.Count - 1; i++)
                    {
                        DataRow dr = dtUserData.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrGiftforadd.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrGiftforadd.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrGiftforadd.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldType");
                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrGiftforadd.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }
                        dr["Cat_Id"] = hdnCatId.Value.ToString();

                        dtUserData.Rows.Add(dr);
                    }
                }
            }







            string SessionTableName = "SpecialGiftForInsert";
            Session.Add(SessionTableName, dtUserData);

            rptrGiftProg.DataSource = dtUserData;
            rptrGiftProg.DataBind();
        }
        else
        {

            foreach (var C in pnlAddGiftProg.Controls)
            {

                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
                {

                    for (int i = 0; i <= rptrGiftforadd.Items.Count - 1; i++)
                    {
                        DataRow dr = SessiondtGift.NewRow();
                        TextBox txtfieldvalue = (TextBox)rptrGiftforadd.Items[i].FindControl("txt");
                        DropDownList ddlfieldvalue = (DropDownList)rptrGiftforadd.Items[i].FindControl("ddl");
                        RadioButtonList rdbfieldvalue = (RadioButtonList)rptrGiftforadd.Items[i].FindControl("rdb");
                        //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
                        HiddenField hdnFieldId = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldId");
                        HiddenField hdnFieldType = (HiddenField)rptrGiftforadd.Items[i].FindControl("hdnFieldType");

                        if (txtfieldvalue != null)
                        {
                            //dr[0] = txtfieldvalue.Text.ToString();
                            //dr[1] = hdnFieldId.Value.ToString();
                            dr["Value"] = txtfieldvalue.Text.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        //*********************01/05/2010**************
                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrGiftforadd.Items[i].FindControl("uc");
                        if (uc != null)
                        {

                            dr["Value"] = uc.Value.ToString();
                            dr["FieldId"] = hdnFieldId.Value.ToString();
                            dr["FieldType"] = hdnFieldType.Value.ToString();
                        }
                        if (ddlfieldvalue != null)
                        {


                            if (ddlfieldvalue.SelectedIndex != -1)
                            {
                                //dr[0] = ddlfieldvalue.SelectedItem.Value.ToString();
                                //dr[1] = hdnFieldId.Value.ToString();
                                dr["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                                dr["FieldId"] = hdnFieldId.Value.ToString();
                                dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                            }

                        }

                        if (rdbfieldvalue != null)
                        {
                            for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                            {
                                if (rdbfieldvalue.Items[r].Selected)
                                {
                                    //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                                    //dr[1] = hdnFieldId.Value.ToString();
                                    dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                                    dr["FieldId"] = hdnFieldId.Value.ToString();
                                    dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                                }

                            }

                        }

                        // dr[4] = hdnCatId.Value.ToString();
                        dr["Cat_Id"] = hdnCatId.Value.ToString();

                        SessiondtGift.Rows.Add(dr);
                    }
                }
            }


            Session.Add("SpecialGiftForInsert", SessiondtGift);
            rptrGiftProg.DataSource = SessiondtGift;
            rptrGiftProg.DataBind();
        }

        PopulateSpecialValue();

    }


    protected void rptrSpecEdu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            HiddenField hdnFieldValue = (HiddenField)e.Item.FindControl("hdnFieldValue");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            DataTable dtspec = schoolcategory.PopulateSpecialFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                txt.Text = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }

            if (hdnFieldType.Value.ToString() == "4")
            {
                //DropDownList ddl = new DropDownList();
                //ddl.ID = "ddl";

                // ddl.CssClass = "textbox_date";

                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.Width = 155;
                ddl.CssClass = "dropdown2";

                if (hdnFieldId.Value.ToString() == "2")
                {
                    // schoolcategory.PopulateEvaluationType(ref ddl);
                    StuListCont.PopulateEvaluationType(ref ddl);
                    ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                }

                if (hdnFieldId.Value.ToString() == "4")
                {
                    StuListCont.PopulateSpecialEduStatus(ref ddl);
                    ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                }

                if (hdnFieldId.Value.ToString() == "5")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                    ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                }

                if (hdnFieldId.Value.ToString() == "6")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                    ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                }

                if (hdnFieldId.Value.ToString() == "9")
                {
                    StuListCont.PopulateSpecialEduExistStatus(ref ddl);
                    ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                }

                maindiv.Controls.Add(ddl);
            }
            //if (hdnFieldType.Value.ToString() == "5")
            //{
            //    Label lbl = new Label();
            //    lbl.ID = "lbl";
            //    //StudentBL stbl2 = new StudentBL();
            //    maindiv.Controls.Add(lbl);
            //}

            //**************01/05/2010*********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                control.ID = "uc";

                control.Value = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(control);

            }

        }
        catch { }

    }

    protected void rptrGiftProg_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            string Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindivgift");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            HiddenField hdnFieldValue = (HiddenField)e.Item.FindControl("hdnFieldValue");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            DataTable dtspec = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }
            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                txt.Text = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(txt);

            }


            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }


            //if (hdnFieldType.Value.ToString() == "5")
            //{
            //    Label lbl = new Label();
            //    lbl.ID = "lbl";
            //    // StudentBL stbl2 = new StudentBL();
            //    maindiv.Controls.Add(lbl);
            //}

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                if (hdnFieldId.Value.ToString() == "1")
                {
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                }

                rdb.RepeatDirection = RepeatDirection.Horizontal;
                rdb.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(rdb);
            }
            if (hdnFieldType.Value.ToString() == "4")
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "dropdown2";
                if (hdnFieldId.Value.ToString() == "2")
                {
                    //schoolcategory.PopulateGiftedCategory(ref ddl);
                    StuListCont.PopulateGiftedCategory(ref ddl);
                }
                ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(ddl);
            }
            //**************01/05/2010*********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                control.ID = "uc";

                control.Value = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(control);

            }




        }
        catch { }
    }

    protected void rptrSpecial_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);

            //  HiddenField hdnfldnametest = (HiddenField)e.Item.FindControl("hdnfldnametest");
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");

            // string test = hdnfldnametest.Value.ToString();

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }

            if (hdnFieldType.Value.ToString() == "4")
            {
                //DropDownList ddl = new DropDownList();
                //ddl.ID = "ddl";

                // ddl.CssClass = "textbox_date";

                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.Width = 155;
                ddl.CssClass = "dropdown2";

                if (hdnFieldId.Value.ToString() == "2")
                {
                    // schoolcategory.PopulateEvaluationType(ref ddl);
                    StuListCont.PopulateEvaluationType(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "4")
                {
                    StuListCont.PopulateSpecialEduStatus(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "5")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "6")
                {
                    StuListCont.PopulateDisabilities(ref ddl);
                }
                if (hdnFieldId.Value.ToString() == "9")
                {
                    StuListCont.PopulateSpecialEduExistStatus(ref ddl);
                }

                maindiv.Controls.Add(ddl);
            }
            if (hdnFieldType.Value.ToString() == "5")
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(lbl);
            }
            //**********01/05/2010***********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                control.ID = "uc";
                //StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(control);
            }


        }
        catch { }


    }

    protected void rptrGiftforadd_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // StudentBL schoolcategory = new StudentBL();
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            //  EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            hdnInitialCatId.Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");

            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                maindiv.Controls.Add(txt);

            }
            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }


            if (hdnFieldType.Value.ToString() == "5")
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                // StudentBL stbl2 = new StudentBL();
                maindiv.Controls.Add(lbl);
            }

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                if (hdnFieldId.Value.ToString() == "1")
                {
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                }

                rdb.RepeatDirection = RepeatDirection.Horizontal;

                maindiv.Controls.Add(rdb);
            }
            if (hdnFieldType.Value.ToString() == "4")
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "dropdown2";
                if (hdnFieldId.Value.ToString() == "2")
                {
                    //schoolcategory.PopulateGiftedCategory(ref ddl);
                    StuListCont.PopulateGiftedCategory(ref ddl);
                }

                maindiv.Controls.Add(ddl);
            }

            //********01/05/2010**********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                control.ID = "uc";



                maindiv.Controls.Add(control);
            }



        }
        catch { }


    }

    public void PopulateSpecialValue()
    {
        DataTable SessiondtGift = (DataTable)Session["SpecialEduForInsert"];
        if (SessiondtGift != null)
        {
            rptrSpecEdu.DataSource = SessiondtGift;
            rptrSpecEdu.DataBind();

        }
        else
        {
            int CatId = Convert.ToInt32(hdnCatId.Value);
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStudentId.Value);
            OpenSISWCFServiceStudentInformationClient StuInfoGSV = new OpenSISWCFServiceStudentInformationClient();
            DataTable dtspecial = StuInfoGSV.GetSpecialValues(SchoolID, StudentID, CatId);



            if (dtspecial.Rows.Count > 0)
            {
                rptrSpecEdu.DataSource = dtspecial;
                rptrSpecEdu.DataBind();
            }
            Session.Add("SpecialEduForInsert", dtspecial);

            StuInfoGSV.Close();
        }
    }
    public void PopulateGiftValue()
    {
        //DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
        //if (SessiondtGift != null)
        //{
        //    rptrGiftProg.DataSource = SessiondtGift;
        //    rptrGiftProg.DataBind();

        //}
        //else
        //{
        //    int CatId = Convert.ToInt32(hdnCatId.Value);
        //    int SchoolID = Convert.ToInt32(Session["SchoolID"]);
        //    int StudentID = Convert.ToInt32(hdnStudentId.Value);
        //    OpenSISWCFServiceStudentInformationClient StuInfoGGV = new OpenSISWCFServiceStudentInformationClient();

        //   DataTable dtGift = StuInfoGGV.GetGiftedValues(SchoolID, StudentID, CatId);
        //    StuInfoGGV.Close();
        //    if (dtGift.Rows.Count > 0)
        //    {
        //        rptrGiftProg.DataSource = dtGift;
        //        rptrGiftProg.DataBind();
        //    }
        //}

        DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];
        if (SessiondtGift != null)
        {
            rptrGiftProg.DataSource = SessiondtGift;
            rptrGiftProg.DataBind();

        }
        else
        {
            int CatId = Convert.ToInt32(hdnCatId.Value);
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStudentId.Value);
            OpenSISWCFServiceStudentInformationClient StuInfoGGV = new OpenSISWCFServiceStudentInformationClient();

            DataTable dtGift = StuInfoGGV.GetGiftedValues(SchoolID, StudentID, CatId);


            //(DataTable)Session["SpecialGiftForInsert"] = dtGift;
            if (dtGift.Rows.Count > 0)
            {
                rptrGiftProg.DataSource = dtGift;
                rptrGiftProg.DataBind();
                StuInfoGGV.Close();
                Session.Add("SpecialGiftForInsert", dtGift);
            }
        }
    }

    protected void btnCancelSpecEdu_Click(object sender, EventArgs e)
    {
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    protected void btncanelgift_Click(object sender, EventArgs e)
    {
        PopulateGiftValue();
        PopulateSpecialValue();
    }

    //****************************************


   

    protected void DataStoreProgram()
    {
        DataTable SessiondtspecialEdu = (DataTable)Session["SpecialEduForInsert"];


        for (int i = 0; i <= rptrSpecEdu.Items.Count - 1; i++)
        {
            //DataRow dr = SessiondtGift.NewRow();
            TextBox txtfieldvalue = (TextBox)rptrSpecEdu.Items[i].FindControl("txt");
            DropDownList ddlfieldvalue = (DropDownList)rptrSpecEdu.Items[i].FindControl("ddl");
            RadioButtonList rdbfieldvalue = (RadioButtonList)rptrSpecEdu.Items[i].FindControl("rdb");
            //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrSpecEdu.Items[i].FindControl("hdnFieldId");
            HiddenField hdnFieldType = (HiddenField)rptrSpecEdu.Items[i].FindControl("hdnFieldType");
            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrSpecEdu.Items[i].FindControl("uc");
            if (txtfieldvalue != null)
            {
                //dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr["Value"] = txtfieldvalue.Text.ToString();
                //dr["FieldId"] = hdnFieldId.Value.ToString();
                //dr["FieldType"] = hdnFieldType.Value.ToString();
                SessiondtspecialEdu.Rows[i]["Value"] = txtfieldvalue.Text.ToString();
            }
            if (uc != null)
            {

                SessiondtspecialEdu.Rows[i]["Value"] = uc.Value.ToString();
            }
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {

                    SessiondtspecialEdu.Rows[i]["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                }

            }

            if (rdbfieldvalue != null)
            {
                for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                {
                    if (rdbfieldvalue.Items[r].Selected)
                    {
                        //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                        //dr["FieldId"] = hdnFieldId.Value.ToString();
                        //dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                        SessiondtspecialEdu.Rows[i]["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                    }

                }

            }

            // dr[4] = hdnCatId.Value.ToString();
            //dr["Cat_Id"] = hdnCatId.Value.ToString();

            // SessiondtGift.Rows.Add(dr);
            SessiondtspecialEdu.AcceptChanges();
        }



        Session.Add("SpecialEduForInsert", SessiondtspecialEdu);
        rptrSpecEdu.DataSource = SessiondtspecialEdu;
        rptrSpecEdu.DataBind();
    }

    protected void DataStoreProgramForGift()
    {
        DataTable SessiondtGift = (DataTable)Session["SpecialGiftForInsert"];


        for (int i = 0; i <= rptrGiftProg.Items.Count - 1; i++)
        {
            //DataRow dr = SessiondtGift.NewRow();
            TextBox txtfieldvalue = (TextBox)rptrGiftProg.Items[i].FindControl("txt");
            DropDownList ddlfieldvalue = (DropDownList)rptrGiftProg.Items[i].FindControl("ddl");
            RadioButtonList rdbfieldvalue = (RadioButtonList)rptrGiftProg.Items[i].FindControl("rdb");
            //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrGiftProg.Items[i].FindControl("hdnFieldId");
            HiddenField hdnFieldType = (HiddenField)rptrGiftProg.Items[i].FindControl("hdnFieldType");
            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrGiftProg.Items[i].FindControl("uc");
            if (txtfieldvalue != null)
            {
                //dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr["Value"] = txtfieldvalue.Text.ToString();
                //dr["FieldId"] = hdnFieldId.Value.ToString();
                //dr["FieldType"] = hdnFieldType.Value.ToString();
                SessiondtGift.Rows[i]["Value"] = txtfieldvalue.Text.ToString();
            }
            if (uc != null)
            {

                SessiondtGift.Rows[i]["Value"] = uc.Value.ToString();
            }
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {

                    SessiondtGift.Rows[i]["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                }

            }

            if (rdbfieldvalue != null)
            {
                for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                {
                    if (rdbfieldvalue.Items[r].Selected)
                    {
                        //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                        //dr["FieldId"] = hdnFieldId.Value.ToString();
                        //dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                        SessiondtGift.Rows[i]["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                    }

                }

            }

            // dr[4] = hdnCatId.Value.ToString();
            //dr["Cat_Id"] = hdnCatId.Value.ToString();

            // SessiondtGift.Rows.Add(dr);
            SessiondtGift.AcceptChanges();
        }



        Session.Add("SpecialGiftForInsert", SessiondtGift);
        rptrGiftProg.DataSource = SessiondtGift;
        rptrGiftProg.DataBind();
    }

    protected void DataStoreEnrInfo()
    {
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        if (SessiondtEnrol != null)
        {
            for (int i = 0; i < gvEnrInfo.Rows.Count; i++)
            {
                HiddenField hdnExitcode = (HiddenField)gvEnrInfo.Rows[i].FindControl("hdnExitcode");
                TextBox txtAttStrtDateEdit = (TextBox)gvEnrInfo.Rows[i].FindControl("txtAttStrtDateEdit");
                DropDownList ddlExitCodeEdit = (DropDownList)gvEnrInfo.Rows[i].FindControl("ddlExitCodeEdit");
                TextBox txtExitDateEdit = (TextBox)gvEnrInfo.Rows[i].FindControl("txtExitDateEdit");
                TextBox txtExitReasonEdit = (TextBox)gvEnrInfo.Rows[i].FindControl("txtExitReasonEdit");
                TextBox txtStrtCondEdit = (TextBox)gvEnrInfo.Rows[i].FindControl("txtStrtCondEdit");

                //DateTime date1 = Convert.ToDateTime(txtAttStrtDateEdit.Text.ToString());
                //DateTime date2 = Convert.ToDateTime(txtExitDateEdit.Text.ToString());

                //string xx = SessiondtEnrol.Rows[i]["temp"].ToString();

                if (!SessiondtEnrol.Columns.Contains("temp"))
                {
                    SessiondtEnrol.Columns.Add("temp");

                }

                if (txtAttStrtDateEdit != null)
                {

                    SessiondtEnrol.Rows[i]["Enr_Start_Date"] = txtAttStrtDateEdit.Text.ToString();
                    SessiondtEnrol.Rows[i]["Enr_End_Date"] = txtExitDateEdit.Text.ToString();
                    SessiondtEnrol.Rows[i]["enrollname"] = ddlExitCodeEdit.SelectedItem.Text;
                    SessiondtEnrol.Rows[i]["Exit_Reason"] = txtExitReasonEdit.Text.ToString();
                    SessiondtEnrol.Rows[i]["Start_Condition"] = txtStrtCondEdit.Text.ToString();
                    SessiondtEnrol.Rows[i]["Enr_Code_Id"] = ddlExitCodeEdit.SelectedItem.Value;
                    SessiondtEnrol.AcceptChanges();
                }


                Session.Add("Enroltable", SessiondtEnrol);
            }
            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();
        }
    }

    protected void gvEnrInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
       
        gvEnrInfo.EditIndex = -1;
       DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
       if (SessiondtEnrol != null)
       {
           gvEnrInfo.DataSource = SessiondtEnrol;
           gvEnrInfo.DataBind();

       }
       
    }

    protected void gvEnrInfo_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        
        gvEnrInfo.EditIndex = e.NewEditIndex;
        DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
        if (SessiondtEnrol != null)
        {
            gvEnrInfo.DataSource = SessiondtEnrol;
            gvEnrInfo.DataBind();

        }
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }
    }

    protected void gvEnrInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        gvEnrInfo.EditIndex = -1;
        DataStoreEnrInfo();
    }


    protected void GVImmunization_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
       
        GVImmunization.EditIndex = -1;
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();

        }

    }

    protected void GVImmunization_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
       
        GVImmunization.EditIndex = e.NewEditIndex;
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();

        }
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }

    }

    protected void GVImmunization_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GVImmunization.EditIndex = -1;
        DataTable SessiondtImmu = (DataTable)Session["ImmuTable"];
        if (SessiondtImmu != null)
        {
            for (int j = 0; j < GVImmunization.Rows.Count; j++)
            {
                TextBox txtDateGVImmunization = (TextBox)GVImmunization.Rows[j].FindControl("txtDateGVImmunization");
                TextBox txtCommentsGVImmunization = (TextBox)GVImmunization.Rows[j].FindControl("txtCommentsGVImmunization");
                DropDownList ddlImmunaizationTypeEdit = (DropDownList)GVImmunization.Rows[j].FindControl("ddlImmunaizationTypeEdit");
                if (txtDateGVImmunization != null)
                {
                    SessiondtImmu.Rows[j]["Date"] = txtDateGVImmunization.Text.ToString();
                    SessiondtImmu.Rows[j]["Comment"] = txtCommentsGVImmunization.Text.ToString();
                    SessiondtImmu.Rows[j]["Type"] = ddlImmunaizationTypeEdit.SelectedItem.Value.ToString();
                    SessiondtImmu.AcceptChanges();
                }
            }
            Session.Add("ImmuTable", SessiondtImmu);
            GVImmunization.DataSource = SessiondtImmu;
            GVImmunization.DataBind();
        }
    }

    //*******************03/05/2010*************
    protected void GVMedicalAlert_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {

        GVMedicalAlert.EditIndex = -1;
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();

        }

    }

    protected void GVMedicalAlert_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];
       
        GVMedicalAlert.EditIndex = e.NewEditIndex;
        DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();

        }
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }

    }

    protected void GVMedicalAlert_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GVMedicalAlert.EditIndex = -1;
         DataTable SessiondtAlert = (DataTable)Session["AlertTable"];
        if (SessiondtAlert != null)
        {
            for (int i = 0; i < GVMedicalAlert.Rows.Count; i++)
            {
                TextBox txtMedicalAlert = (TextBox)GVMedicalAlert.Rows[i].FindControl("txtMedicalAlert");
                if(txtMedicalAlert!=null)
                {
                SessiondtAlert.Rows[i]["Alert"] = txtMedicalAlert.Text.ToString();
                SessiondtAlert.AcceptChanges();
                }
            }
            Session.Add("AlertTable", SessiondtAlert);
            GVMedicalAlert.DataSource = SessiondtAlert;
            GVMedicalAlert.DataBind();
        }
       
    }

    protected void GVNurseVisitRec_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {

        GVNurseVisitRec.EditIndex = -1;
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();

        }

    }

    protected void GVNurseVisitRec_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //DataTable SessiondtEnrol = (DataTable)Session["Enroltable"];

        GVNurseVisitRec.EditIndex = e.NewEditIndex;
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();

        }
        int Treepos = Convert.ToInt32(TreeView1.SelectedNode.Value.Split(",".ToCharArray())[1]);
        if ((Treepos + 1) == Convert.ToInt32(TreeView1.Nodes.Count))
        {
            btnUpdate.Visible = true;
            btnPrev.Visible = true;
            btnNext.Visible = false;
        }
        else
        {
            btnUpdate.Visible = false;
            btnPrev.Visible = true;
            btnNext.Visible = true;
        }

    }

    protected void GVNurseVisitRec_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GVNurseVisitRec.EditIndex = -1;
        DataTable SessiondtNurseVisit = (DataTable)Session["NurseVisitTable"];
        if (SessiondtNurseVisit != null)
        {
            for (int i = 0; i < GVNurseVisitRec.Rows.Count; i++)
            {
                TextBox txtNVRDateEdit = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRDateEdit");
                TextBox txtNVRTimeInEdit = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRTimeInEdit");
                TextBox txtNVRTimeOutEdit = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRTimeOutEdit");
                TextBox txtNVRreasonEdit = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRreasonEdit");
                TextBox txtNVRResultEdit = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRResultEdit");
                TextBox txtNVRComments = (TextBox)GVNurseVisitRec.Rows[i].FindControl("txtNVRComments");
                if (txtNVRDateEdit != null)
                {
                    SessiondtNurseVisit.Rows[i]["Date"] = txtNVRDateEdit.Text.ToString();
                    SessiondtNurseVisit.Rows[i]["TimeIn"] = txtNVRTimeInEdit.Text.ToString();
                    SessiondtNurseVisit.Rows[i]["TimeOut"] = txtNVRTimeOutEdit.Text.ToString();
                    SessiondtNurseVisit.Rows[i]["Reason"] = txtNVRreasonEdit.Text.ToString();
                    SessiondtNurseVisit.Rows[i]["Result"] = txtNVRResultEdit.Text.ToString();
                    SessiondtNurseVisit.Rows[i]["Comments"] = txtNVRComments.Text.ToString();
                    SessiondtNurseVisit.AcceptChanges();
                }
            }


            Session.Add("NurseVisitTable", SessiondtNurseVisit);
            GVNurseVisitRec.DataSource = SessiondtNurseVisit;
            GVNurseVisitRec.DataBind();
        }

    }





    //*************05/05/2010**************
    //protected void PopulateVaccinationForEdit()
    //{
    //    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
       
    //    DataTable dtVaccination = new DataTable();
    //    dtVaccination.Columns.Add("Vaccination_Code");
    //    dtVaccination.Columns.Add("Vaccination_Name");
    //    dtVaccination.Columns.Add("Vaccination_Date");
    //    dtVaccination.Columns.Add("Vaccination_Expiry_Date");
    //    dtVaccination.Columns.Add("Waiver");

    //    DataRow drvaccination = dtVaccination.NewRow();
    //    for (int i = 0; i < GVVccination.Rows.Count; i++)
    //    {

    //        Label lblVaccinationCode = (Label)GVVccination.Rows[i].FindControl("lblVaccinationCode");
    //        Label lblVaccinationName = (Label)GVVccination.Rows[i].FindControl("lblVaccinationName");
    //        Label lblVaccinationDate = (Label)GVVccination.Rows[i].FindControl("lblVaccinationDate");
    //        Label lblVaccinationExpiryDate = (Label)GVVccination.Rows[i].FindControl("lblVaccinationExpiryDate");
    //        Label lblWaiver = (Label)GVVccination.Rows[i].FindControl("lblWaiver");
    //        drvaccination[0] = lblVaccinationCode.Text.ToString();
    //        drvaccination[1] = lblVaccinationName.Text.ToString();
    //        drvaccination[2] = lblVaccinationDate.Text.ToString();
    //        drvaccination[3] = lblVaccinationExpiryDate.Text.ToString();
    //        drvaccination[4] = lblWaiver.Text.ToString();
    //        NurseVisitRowId = i;
          
    //    }

    //    dtVaccination.Rows.Add(drvaccination);
    //    Session.Add("Vaccination", dtVaccination);
    //    DataTable dtVcea = new DataTable();
     
    //    dtVcea = schoolcategory.GetVaccinationFieldsStudentBusiness(Convert.ToInt32(Session["SchoolID"]), Convert.ToInt32(hdnCatId.Value));
        
    //    rptrVaceFieldEdit.DataSource = dtVcea;
    //    rptrVaceFieldEdit.DataBind();
    //    PopulateVaccinationFieldData();
       
    //}

    //protected void StoreVaccinationFieldDataINEdit()
    //{
    //    try
    //    {
    //        DataTable SessiondtVaccination = (DataTable)Session["VaccinationForInsert"];
    //        if (SessiondtVaccination == null)
    //        {
    //            DataTable dtUserData = new DataTable();
    //            dtUserData.Columns.Add("Value");
    //            dtUserData.Columns.Add("FieldId");
    //            dtUserData.Columns.Add("FieldCatagory");

    //            foreach (var C in panel_Vaccination.Controls)
    //            {

    //                if (object.ReferenceEquals(C.GetType(), typeof(Repeater)))
    //                {

    //                    for (int i = 0; i <= rptrVaceFieldEdit.Items.Count - 1; i++)
    //                    {
    //                        DataRow drvacc = dtUserData.NewRow();
    //                        TextBox txtfieldvalue = (TextBox)rptrVaceFieldEdit.Items[i].FindControl("txt");
    //                        HiddenField hdnFieldId = (HiddenField)rptrVaceFieldEdit.Items[i].FindControl("hdnFieldId");
    //                        DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVaceFieldEdit.Items[i].FindControl("uc");
    //                        if (txtfieldvalue != null)
    //                        {
    //                            drvacc[0] = txtfieldvalue.Text.ToString();
    //                            drvacc[1] = hdnFieldId.Value.ToString();
    //                            txtfieldvalue.Text = "";
    //                        }
    //                        if (uc != null)
    //                        {
    //                            drvacc[0] = uc.Value.ToString();
    //                            drvacc[1] = hdnFieldId.Value.ToString();
    //                            uc.Value = "";
    //                        }
    //                        dtUserData.Rows.Add(drvacc);
    //                    }
    //                }
    //            }

    //            Session.Add("VaccinationForInsert", dtUserData);
    //        }
    //        else
    //        {

    //        }
    //    }
    //    catch
    //    {
    //    }
    //}

    //***********************************rptrVccination_ItemDataBound
    protected void rptrVccination_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
        try
        {
            // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();


            // EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            OpenSISWCFServiceStudentFormLayoutClient categoryfields = new OpenSISWCFServiceStudentFormLayoutClient();
            string Value = hdnCatId.Value;
            int CatId = Convert.ToInt32(hdnCatId.Value);
            //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindivgift");
            HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            HiddenField hdnFieldValue = (HiddenField)e.Item.FindControl("hdnFieldValue");
            Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");

            //multilangual*********

            //DataTable dtspec = schoolcategory.PopulateGiftFieldStudentBusiness(SchoolID, Session["MLUICulture"].ToString());
            DataTable dtspec = schoolcategory.GetVaccinationFieldsStudentBusiness(SchoolID, CatId);
            for (int i = 0; i < dtspec.Rows.Count; i++)
            {
                if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
                {
                    lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
                }
            }
            if (hdnFieldType.Value.ToString() == "1")
            {
                TextBox txt = new TextBox();
                txt.ID = "txt";
                txt.Width = 150;
                txt.Text = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(txt);

            }


            if (hdnFieldType.Value.ToString() == "2")
            {
                CheckBoxList chk = new CheckBoxList();
                chk.ID = "chk";
                chk.RepeatDirection = RepeatDirection.Horizontal;
                maindiv.Controls.Add(chk);
            }


            //if (hdnFieldType.Value.ToString() == "5")
            //{
            //    Label lbl = new Label();
            //    lbl.ID = "lbl";
            //    // StudentBL stbl2 = new StudentBL();
            //    maindiv.Controls.Add(lbl);
            //}

            if (hdnFieldType.Value.ToString() == "3")
            {
                RadioButtonList rdb = new RadioButtonList();
                rdb.ID = "rdb";

                if (hdnFieldId.Value.ToString() == "1")
                {
                    //  schoolcategory.PopulateYesNo(ref rdb);
                    StuListCont.PopulateYesNo(ref rdb);
                }

                rdb.RepeatDirection = RepeatDirection.Horizontal;
                rdb.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(rdb);
            }
            if (hdnFieldType.Value.ToString() == "4")
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "ddl";
                ddl.CssClass = "dropdown2";
                if (hdnFieldId.Value.ToString() == "2")
                {
                    //schoolcategory.PopulateGiftedCategory(ref ddl);
                    StuListCont.PopulateGiftedCategory(ref ddl);
                }
                ddl.Items.FindByValue(hdnFieldValue.Value).Selected = true;
                maindiv.Controls.Add(ddl);
            }
            //**************01/05/2010*********
            if (hdnFieldType.Value.ToString() == "6")
            {
                var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");
                control.ID = "uc";

                control.Value = hdnFieldValue.Value.ToString();
                maindiv.Controls.Add(control);

            }




        }
        catch { }
    }


    //****
    protected void DataStoreProgramForVaccination()
    {
        DataTable VaccinationForInsert = (DataTable)Session["VaccinationForInsert"];


        for (int i = 0; i <= rptrVccination.Items.Count - 1; i++)
        {
            //DataRow dr = SessiondtGift.NewRow();
            TextBox txtfieldvalue = (TextBox)rptrVccination.Items[i].FindControl("txt");
            DropDownList ddlfieldvalue = (DropDownList)rptrVccination.Items[i].FindControl("ddl");
            RadioButtonList rdbfieldvalue = (RadioButtonList)rptrVccination.Items[i].FindControl("rdb");
            //TextBox txtfieldvalue = (TextBox)rptrSpecial.Items[i].FindControl("txt");
            HiddenField hdnFieldId = (HiddenField)rptrVccination.Items[i].FindControl("hdnFieldId");
            HiddenField hdnFieldType = (HiddenField)rptrVccination.Items[i].FindControl("hdnFieldType");
            DatePicker.DatePicker uc = (DatePicker.DatePicker)rptrVccination.Items[i].FindControl("uc");
            if (txtfieldvalue != null)
            {
                //dr[0] = txtfieldvalue.Text.ToString();
                //dr[1] = hdnFieldId.Value.ToString();
                //dr["Value"] = txtfieldvalue.Text.ToString();
                //dr["FieldId"] = hdnFieldId.Value.ToString();
                //dr["FieldType"] = hdnFieldType.Value.ToString();
                VaccinationForInsert.Rows[i]["Value"] = txtfieldvalue.Text.ToString();
            }
            if (uc != null)
            {

                VaccinationForInsert.Rows[i]["Value"] = uc.Value.ToString();
            }
            if (ddlfieldvalue != null)
            {


                if (ddlfieldvalue.SelectedIndex != -1)
                {

                    VaccinationForInsert.Rows[i]["Value"] = ddlfieldvalue.SelectedItem.Value.ToString();
                }

            }

            if (rdbfieldvalue != null)
            {
                for (int r = 0; r < rdbfieldvalue.Items.Count; r++)
                {
                    if (rdbfieldvalue.Items[r].Selected)
                    {
                        //dr[0] = rdbfieldvalue.SelectedItem.Value.ToString();

                        //dr[1] = hdnFieldId.Value.ToString();
                        //dr["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                        //dr["FieldId"] = hdnFieldId.Value.ToString();
                        //dr["FieldType"] = hdnFieldType.Value.ToString(); ;
                        VaccinationForInsert.Rows[i]["Value"] = rdbfieldvalue.SelectedItem.Value.ToString();
                    }

                }

            }

            // dr[4] = hdnCatId.Value.ToString();
            //dr["Cat_Id"] = hdnCatId.Value.ToString();

            // SessiondtGift.Rows.Add(dr);
            VaccinationForInsert.AcceptChanges();
        }



        Session.Add("VaccinationForInsert", VaccinationForInsert);
        rptrVccination.DataSource = VaccinationForInsert;
        rptrVccination.DataBind();
    }

    public void PopulateVccinationValue()
    {


        DataTable SessiondtGift = (DataTable)Session["VaccinationForInsert"];
        if (SessiondtGift != null)
        {
            rptrVccination.DataSource = SessiondtGift;
            rptrVccination.DataBind();

        }
        else
        {

            IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
            DataTable dtVcea = new DataTable();
            dtVcea = schoolcategory.GetVaccinationFieldsValue(Convert.ToInt32(Session["SchoolID"]), Convert.ToInt32(hdnStudentId.Value));
            
            //(DataTable)Session["SpecialGiftForInsert"] = dtGift;
            if (dtVcea.Rows.Count > 0)
            {
                rptrVccination.DataSource = dtVcea;
                rptrVccination.DataBind();
                schoolcategory.Close();
                Session.Add("VaccinationForInsert", dtVcea);
            }
        }
    }
}
